25 lines
566 B
Raku
25 lines
566 B
Raku
use lib $*PROGRAM.parent.parent;
|
|
use Lib;
|
|
|
|
sub safe($report) {
|
|
my $diff = $report.rotor(2=>-1).map({ $_[1] - $_[0] }).List;
|
|
so (1 <= $diff.all <= 3 or -3 <= $diff.all <= -1)
|
|
}
|
|
|
|
grammar Solution does AOC {
|
|
token TOP { (^^ <report> \n)+ { make $/[0]>><report>>>.made; } }
|
|
token report { (<num> \h*)+ { make $/[0]>><num>>>.made;} }
|
|
token num { \d+ { make val($/.Str) } }
|
|
|
|
method part1(::?CLASS:U: $v) {
|
|
$v.map(&safe).Bag{True};
|
|
}
|
|
|
|
method part2(::?CLASS:U: $v) {
|
|
$v.map({so safe(.combinations(.elems - 1).any)}).Bag{True}
|
|
}
|
|
}
|
|
|
|
|
|
Solution.main()
|