Quick actions

cmd+k|ctrl+k

Navigation

Languages

AoC2024, day 2

Snippet info

Language

Raku

Visibility

public

Author

seaker

Created

2024-12-02T06:23:34.033489Z

Updated

2024-12-02T08:05:06.546411Z

# https://adventofcode.com/2024/day/2

my ($cnt-p1, $cnt-p2) X= 0;
for $*IN.lines».words -> @a {
    ++$cnt-p1 if @a.&safe;
    ++$cnt-p2 if @a.&safe || @a.combinations(+@a-1).map(*.&safe).any;
}
put 'part 1: ', $cnt-p1;
put 'part 2: ', $cnt-p2;

my method safe(*@a : --> Bool:D) {
    so -3 ≤ $_ < 0 || 0 < $_ ≤ 3 with all(@a.head(*-1) Z- @a.tail(*-1))
}
INFO