Skip to content

Instantly share code, notes, and snippets.

@colomon
Created July 1, 2014 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colomon/adf4d949d1835730ba65 to your computer and use it in GitHub Desktop.
Save colomon/adf4d949d1835730ba65 to your computer and use it in GitHub Desktop.
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