Created
July 1, 2014 11:03
-
-
Save colomon/adf4d949d1835730ba65 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub next-happy($n) { [+] $n.comb.map(* ** 2) } | |
sub no-loop-found(@n) { | |
my $seen = SetHash.new; | |
for @n -> $n { | |
return False if $seen{$n}; | |
$seen{$n} = True; | |
} | |
return True; | |
} | |
sub is-happy($n) { | |
no-loop-found($n, &next-happy ... 1); | |
} | |
say (1..100).grep({ is-happy($_) }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment