From a0a507b89c3d8a1a82764ea2521d1b0ccbecc46f Mon Sep 17 00:00:00 2001 From: eutro Date: Tue, 3 Dec 2024 08:21:15 +0000 Subject: [PATCH] Day 3 --- days/day03.st | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 days/day03.st diff --git a/days/day03.st b/days/day03.st new file mode 100644 index 0000000..14accf9 --- /dev/null +++ b/days/day03.st @@ -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