RosettaCodeData/Task/Prime-decomposition/Slate/prime-decomposition.slate
Ingy döt Net b83f433714 tasks a-s
2013-04-10 23:57:08 -07:00

15 lines
401 B
Text

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."
].