Happy numbers: Difference between revisions

Line 1,023:
say join ' ', grep(&happy, 1 .. *)[^8];
</lang>
Here's another approach that uses a different set of tricks including lazy lists, gather/take, repeat-until, and the cross metaoperator X.
<lang perl6>my @happy := gather for 2..* -> $number {
my %stopper = 1 => 1;
my $n = $number;
repeat until %stopper{$n}++ {
$n = [+] $n.comb X** 2;
}
take $number if $n == 1;
}
 
say ~@happy[^8];
</lang>
There's more than one way to do it...
 
=={{header|PHP}}==
Anonymous user