Factors of an integer: Difference between revisions

(→‎{{header|Oz}}: avoid duplicate factor for square numbers)
Line 198:
( scratchpad ) 24 divisors .
{ 1 2 3 4 6 8 12 24 }
=={{Header|Forth}}==
This is a slightly optimized algorithm, since it realizes there are no factors between n/2 and n. The values are saved on the stack and - in true Forth fashion - printed in descending order.
<lang Forth>: factors dup 2/ 1+ 1 do dup i mod 0= if i swap then loop ;
: .factors factors begin dup dup . 1 <> while drop repeat drop cr ;
 
45 .factors
53 .factors
64 .factors
100 .factors</lang>
 
=={{Header|Haskell}}==
Using D. Amos module Primes [http://www.polyomino.f2s.com/david/haskell/codeindex.html] for finding prime factors
374

edits