Advent of Code 2024, Day 3

When I did my submission, I did the filtering as an “external preprocessing” step with grep and did the rest in Python. It reminded me of previous years, where I had to do some “external postprocessing” with Wolfram Alpha sometimes.

Instead of this hybrid approach, the code I give below runs entirely in the Unix shell, without any Python. This was the only day this year where I did not use Python for everything.

Part 1 (0.01 seconds)

grep -o 'mul([0-9]\+,[0-9]\+)' |
sed '
	s/mul(/s += /
	s/,/ * /
	s/)//
	$s/$/\ns/
' |
bc

Part 2 (0.01 seconds)

grep -o -e 'mul([0-9]\+,[0-9]\+)' -e 'do()' -e 'don'\''t()' |
sed '
	1s/^/x = 1\n/
	s/do()/x = 1/
	s/don'\''t()/x = 0/
	s/mul(/s += x * /
	s/,/ * /
	s/)//
	$s/$/\ns/
' |
bc

2024-12-27

Proxy Information
Original URL
gemini://dkalak.de/aoc/03.gmi
Status Code
Success (20)
Meta
text/gemini; lang=en
Capsule Response Time
170.943783 milliseconds
Gemini-to-HTML Time
0.297835 milliseconds

This content has been proxied by September (ba2dc).