28 lines
723 B
Raku
28 lines
723 B
Raku
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()
|