my $calculator = sub ($n is rw) { return ($n == 1) ?? 1 !! $n %% 2 ?? $n div 2 !! $n * 3 + 1 }; sub next (%this, &get_next) { return %this if %this. == 1; %this..=&get_next; %this.++; return %this; }; my @hailstones = map { %(value => $_, count => 0) }, 1 .. 12; while not all( map { $_. }, @hailstones ) == 1 { say [~] map { $_..fmt("%4s") }, @hailstones; @hailstones[$_].=&next($calculator) for ^@hailstones; } say 'Counts'; say [~] map { $_..fmt("%4s") }, @hailstones;