Day 3
This commit is contained in:
27
day-03/main.raku
Normal file
27
day-03/main.raku
Normal file
@@ -0,0 +1,27 @@
|
||||
use lib $*PROGRAM.parent.parent;
|
||||
use Lib;
|
||||
|
||||
grammar Solution does AOC {
|
||||
method aocparse(::?CLASS:U: $content) {
|
||||
($content ~~ m:g/ <Solution::instr> /)>><Solution::instr>>>.made
|
||||
}
|
||||
|
||||
proto token instr {*}
|
||||
token instr:i<dont> { 'don\'t()' { make False }}
|
||||
token instr:i<do> { 'do()' { make True }}
|
||||
token instr:i<mul> { 'mul(' <num> ',' <num> ')' { make $/<num>>>.made }}
|
||||
token num { \d ** 1..3 { make val($/.Str) }}
|
||||
|
||||
method part1(::?CLASS:U: $v) {
|
||||
my @x = $v.grep({ .isa(List) });
|
||||
[+] (@x>>[0] <<*>> @x>>[1])
|
||||
}
|
||||
|
||||
method part2(::?CLASS:U: $v) {
|
||||
my @x = $v.grep({ state $do = True; $do = $_ if .isa(Bool); $do and .isa(List) });
|
||||
[+] (@x>>[0] <<*>> @x>>[1])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Solution.main()
|
||||
Reference in New Issue
Block a user