primes/primes.st

30 lines
506 B
Smalltalk
Raw Normal View History

2011-03-08 07:01:27 +00:00
" 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
]
]
].
!