Basic structure; day 1, 2

This commit is contained in:
bluepython508
2024-12-03 10:34:33 +00:00
commit b24b64a22c
12 changed files with 2164 additions and 0 deletions

24
day-02/main.raku Normal file
View File

@@ -0,0 +1,24 @@
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()