Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
35
Task/Happy-numbers/Fantom/happy-numbers.fantom
Normal file
35
Task/Happy-numbers/Fantom/happy-numbers.fantom
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
class Main
|
||||
{
|
||||
static Bool isHappy (Int n)
|
||||
{
|
||||
Int[] record := [,]
|
||||
while (n != 1 && !record.contains(n))
|
||||
{
|
||||
record.add (n)
|
||||
// find sum of squares of digits
|
||||
newn := 0
|
||||
while (n > 0)
|
||||
{
|
||||
newn += (n.mod(10) * n.mod(10))
|
||||
n = n.div(10)
|
||||
}
|
||||
n = newn
|
||||
}
|
||||
return (n == 1)
|
||||
}
|
||||
|
||||
public static Void main ()
|
||||
{
|
||||
i := 1
|
||||
count := 0
|
||||
while (count < 8)
|
||||
{
|
||||
if (isHappy (i))
|
||||
{
|
||||
echo (i)
|
||||
count += 1
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue