Add all the A tasks
This commit is contained in:
parent
2dd7375f96
commit
051504d65b
1608 changed files with 18584 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