June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
44
Task/Happy-numbers/Elena/happy-numbers.elena
Normal file
44
Task/Happy-numbers/Elena/happy-numbers.elena
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import extensions.
|
||||
import system'collections.
|
||||
import system'routines.
|
||||
|
||||
isHappy = (:n)<int>
|
||||
[
|
||||
list<int> cache := list<int>(5).
|
||||
int sum := 0.
|
||||
int num := n.
|
||||
while (num != 1)
|
||||
[
|
||||
if (cache indexOfElement:num != -1)
|
||||
[
|
||||
^ false
|
||||
].
|
||||
cache append(num).
|
||||
while (num != 0)
|
||||
[
|
||||
int digit := num mod:10.
|
||||
sum += (digit*digit).
|
||||
num /= 10
|
||||
].
|
||||
num := sum.
|
||||
sum := 0
|
||||
].
|
||||
|
||||
^ true
|
||||
].
|
||||
|
||||
program =
|
||||
[
|
||||
list<int> happynums := list<int>(8).
|
||||
int num := 1.
|
||||
while (happynums length < 8)
|
||||
[
|
||||
if (isHappy eval(num))
|
||||
[
|
||||
happynums append(num)
|
||||
].
|
||||
|
||||
num += 1
|
||||
].
|
||||
console printLine("First 8 happy numbers: ", happynums).
|
||||
].
|
||||
Loading…
Add table
Add a link
Reference in a new issue