Factors of an integer: Difference between revisions

Content deleted Content added
Mlochbaum (talk | contribs)
→‎{{header|BQN}}: Version based on prime factorization
→‎{{header|Sather}}: Use an iterator for factor generation (sadly means factors aren't ordered, but avoids allocation)
Line 5,996:
 
=={{header|Sather}}==
 
{{trans|C++}}
<lang sather>class MAIN is
 
factors!(n :INT):ARRAY{INT} is
f:ARRAY{INT}yield 1;
f := #;
f := f.append(|1|);
f := f.append(|n|);
loop i ::= 2.upto!( n.flt.sqrt.int );
if n%i = 0 then
fyield := f.append(|i|);
if (i*i) /= n then f := f.append(|n / i|); end;
yield n / i;
f := # end;
end;
end;
f.sortyield n;
return f;
end;
 
Line 6,018 ⟶ 6,016:
loop l ::= a.elt!;
#OUT + "factors of " + l + ": ";
rloop ri ::= factors!(l);
loop ri ::= r.elt!;
#OUT + ri + " ";
end;
Line 6,025 ⟶ 6,022:
end;
end;
end;</lang>
</lang>
 
=={{header|Scala}}==