Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
18
Task/Arithmetic-Rational/Smalltalk/arithmetic-rational.st
Normal file
18
Task/Arithmetic-Rational/Smalltalk/arithmetic-rational.st
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
| sum |
|
||||
2 to: (2 raisedTo: 19) do: [ :candidate |
|
||||
sum := candidate reciprocal.
|
||||
2 to: (candidate sqrt) do: [ :factor |
|
||||
( (candidate \\ factor) = 0 )
|
||||
ifTrue: [
|
||||
sum := sum + (factor reciprocal) + ((candidate / factor) reciprocal)
|
||||
]
|
||||
].
|
||||
( (sum denominator) = 1 )
|
||||
ifTrue: [
|
||||
('Sum of recipr. factors of %1 = %2 exactly %3' %
|
||||
{ candidate printString .
|
||||
(sum asInteger) printString .
|
||||
( sum = 1 ) ifTrue: [ 'perfect!' ]
|
||||
ifFalse: [ ' ' ] }) displayNl
|
||||
]
|
||||
].
|
||||
Loading…
Add table
Add a link
Reference in a new issue