Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
20
Task/Happy-numbers/Nim/happy-numbers.nim
Normal file
20
Task/Happy-numbers/Nim/happy-numbers.nim
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import intsets
|
||||
|
||||
proc happy(n: int): bool =
|
||||
var
|
||||
n = n
|
||||
past = initIntSet()
|
||||
while n != 1:
|
||||
let s = $n
|
||||
n = 0
|
||||
for c in s:
|
||||
let i = ord(c) - ord('0')
|
||||
n += i * i
|
||||
if n in past:
|
||||
return false
|
||||
past.incl(n)
|
||||
return true
|
||||
|
||||
for x in 0..31:
|
||||
if happy(x):
|
||||
echo x
|
||||
Loading…
Add table
Add a link
Reference in a new issue