Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
22
Task/Happy-numbers/CoffeeScript/happy-numbers.coffee
Normal file
22
Task/Happy-numbers/CoffeeScript/happy-numbers.coffee
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
happy = (n) ->
|
||||
seen = {}
|
||||
while true
|
||||
n = sum_digit_squares(n)
|
||||
return true if n == 1
|
||||
return false if seen[n]
|
||||
seen[n] = true
|
||||
|
||||
sum_digit_squares = (n) ->
|
||||
sum = 0
|
||||
for c in n.toString()
|
||||
d = parseInt(c)
|
||||
sum += d*d
|
||||
sum
|
||||
|
||||
i = 1
|
||||
cnt = 0
|
||||
while cnt < 8
|
||||
if happy(i)
|
||||
console.log i
|
||||
cnt += 1
|
||||
i += 1
|
||||
Loading…
Add table
Add a link
Reference in a new issue