Count in factors: Difference between revisions

no edit summary
No edit summary
Line 2,035:
print ""
end</lang>
 
=={{header|M2000 Interpreter}}==
Decompose function now return array (in number decomposition task return an inventory list).
 
<lang M2000 Interpreter>
Module Count_in_factors {
Inventory Known1=2@, 3@
IsPrime=lambda Known1 (x as decimal) -> {
=0=1
if exist(Known1, x) then =1=1 : exit
if x<=5 OR frac(x) then {if x == 2 OR x == 3 OR x == 5 then Append Known1, x : =1=1
Break}
if frac(x/2) else exit
if frac(x/3) else exit
x1=sqrt(x):d = 5@
{if frac(x/d ) else exit
d += 2: if d>x1 then Append Known1, x : =1=1 : exit
if frac(x/d) else exit
d += 4: if d<= x1 else Append Known1, x : =1=1: exit
loop
}
}
decompose=lambda IsPrime (n as decimal) -> {
Factors=(,)
{
k=2@
While frac(n/k)=0
n/=k
Append Factors, (k,)
End While
if n=1 then exit
k++
While frac(n/k)=0
n/=k
Append Factors, (k,)
End While
if n=1 then exit
{
k+=2
while not isprime(k) {k+=2}
While frac(n/k)=0
n/=k : Append Factors, (k,)
End While
if n=1 then exit
loop
}
}
=Factors
}
fold=lambda (a, f$)->{
Push if$(len(f$)->f$+"x","")+str$(a,"")
}
Print "1=1"
i=1@
do
i++
Print str$(i,"####")+"="+Decompose(i)#fold$(fold,"")
always
}
Count_in_factors
</lang>
 
=={{header|M4}}==
Anonymous user