RosettaCodeData/Task/Hailstone-sequence/Perl-6/hailstone-sequence.pl6

9 lines
292 B
Raku
Raw Permalink Normal View History

2013-04-10 22:43:41 -07:00
sub hailstone($n) { $n, { $_ %% 2 ?? $_ div 2 !! $_ * 3 + 1 } ... 1 }
my @h = hailstone(27);
say "Length of hailstone(27) = {+@h}";
say ~@h;
2019-09-12 10:33:56 -07:00
my $m = max ( (1..99_999).race.map: { +hailstone($_) => $_ } );
2016-12-05 22:15:40 +01:00
say "Max length {$m.key} was found for hailstone({$m.value}) for numbers < 100_000";