Day 3
This commit is contained in:
parent
3b194c4302
commit
a0a507b89c
1 changed files with 24 additions and 0 deletions
24
days/day03.st
Normal file
24
days/day03.st
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
Object subclass: VM [
|
||||
| enabled total |
|
||||
initialize [ enabled := true. total := 0. ]
|
||||
total [ ^total ]
|
||||
|
||||
interpret: insns
|
||||
[ insns do: [
|
||||
:it |
|
||||
(it scanf: 'mul(%d, %d)'
|
||||
with: [
|
||||
:l :r |
|
||||
enabled ifTrue: [
|
||||
total := total + (l * r)
|
||||
]
|
||||
])
|
||||
ifNil: [ enabled := (it = 'do()') ]. ].
|
||||
^total ]
|
||||
]
|
||||
|
||||
AOC input: [ stdin contents ];
|
||||
part1: 'mul\([0-9]{1,3},[0-9]{1,3}\)';
|
||||
part2: 'mul\([0-9]{1,3},[0-9]{1,3}\)|do\(\)|don''t\(\)';
|
||||
result: [ :inp :re | VM new interpret: (inp chain allOccurrencesOfRegex: re) ];
|
||||
finish
|
||||
Loading…
Add table
Reference in a new issue