29 lines
631 B
Text
29 lines
631 B
Text
variable happy_count := 0;
|
|
outer:
|
|
iterate(x; [1...+oo])
|
|
{
|
|
variable seen := <<(* --> false)>>;
|
|
variable now := x;
|
|
while (true)
|
|
{
|
|
if (seen[now])
|
|
{
|
|
if (now == 1)
|
|
{
|
|
++happy_count;
|
|
print(x, " is happy.\n");
|
|
if (happy_count == 8)
|
|
break from outer;;
|
|
};
|
|
break;
|
|
};
|
|
seen[now] := true;
|
|
variable new := 0;
|
|
while (now != 0)
|
|
{
|
|
new += (now % 10) * (now % 10);
|
|
now /::= 10;
|
|
};
|
|
now := new;
|
|
};
|
|
};
|