30 lines
506 B
Smalltalk
30 lines
506 B
Smalltalk
|
" Smalltalk version of a prime number finder
|
||
|
<haplo@mindstab.net>"
|
||
|
|
||
|
| Max |
|
||
|
|
||
|
Smalltalk arguments size < 1
|
||
|
ifTrue: [
|
||
|
'Usage: primes.st [Max]' printNl.
|
||
|
]
|
||
|
ifFalse: [
|
||
|
|
||
|
Max := (Smalltalk arguments at: 1) asInteger.
|
||
|
3 to: Max by: 2 do: [ :number |
|
||
|
LowMax := (number sqrt) rounded.
|
||
|
IsPrime := true.
|
||
|
3 to: LowMax by: 2 do: [ :factor |
|
||
|
((number rem: factor) == 0)
|
||
|
ifTrue: [
|
||
|
IsPrime := false
|
||
|
]
|
||
|
].
|
||
|
|
||
|
IsPrime
|
||
|
ifTrue: [
|
||
|
number printNl
|
||
|
]
|
||
|
]
|
||
|
].
|
||
|
!
|