This commit is contained in:
bluepython508
2024-12-03 11:16:12 +00:00
parent b24b64a22c
commit ec51a3b67a
6 changed files with 41 additions and 1 deletions

27
day-03/main.raku Normal file
View 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()