about summary refs log tree commit diff
path: root/aoc/2021/11/part-one.raku
blob: 88cf4eb2e645551597d258e6b8df79b852cfaca9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
sub adj($i, $k) { [&&] map -2 < * < 2, [«-»] map { polymod $_: 10 }, ($i, $k) }
sub flash(@level, $count) {
    my $i = first * > 9, @level, :k;
    return ({ max $_, 0 } for @level), $count without $i;
    flash ({ $i == $^k ?? -8 !! $^v + adj $i, $^k } for @level.kv), $count + 1
}
sub step($times, @level, $count=0) {
    return $count unless $times > 0;
    step $times - 1, |flash @level »+» 1, $count
}
my $input = lines slurp 'input';
put step 100, $input.join.comb