# usage: raku day2-part2.raku [path/to/input] (default: ../data/day2.txt) my $path = @*ARGS[0] // '../data/day2.txt'; my %left = $path.IO.slurp.trim.comb.Bag; my @cycle = ; my ($pos, $total) = (0, 0); while %left.elems { my $c = %left.keys.max({ (@cycle.first(* eq $_, :k) - $pos) % 6 || 6 }); my $d = (@cycle.first(* eq $c, :k) - $pos) % 6 || 6; $total += $d; $pos = @cycle.first(* eq $c, :k); %left{$c}--; %left{$c}:delete if %left{$c} == 0; } say $total;