15 lines
404 B
Text
15 lines
404 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."
|
|
].
|