Basic structure; day 1, 2
This commit is contained in:
24
day-02/main.raku
Normal file
24
day-02/main.raku
Normal 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()
|
||||
Reference in New Issue
Block a user