RosettaCodeData/Task/Prime-decomposition/Slate/prime-decomposition.slate

16 lines
401 B
Text
Raw Permalink Normal View History

2013-04-10 23:57:08 -07:00
n@(Integer traits) primesDo: block
"Decomposes the Integer into primes, applying the block to each (in increasing
order)."
[| div next remaining |
div: 2.
next: 3.
remaining: n.
[[(remaining \\ div) isZero]
whileTrue:
[block applyTo: {div}.
remaining: remaining // div].
remaining = 1] whileFalse:
[div: next.
next: next + 2] "Just look at the next odd integer."
].