Slow burner.
First part was a straightforward implementation
of a runner, the code is extracted to `org_version()`.
Part 2 was way more tricky. Like many others, trying
to understand the program felt necessary. This
intepretation is this:
"""Python version of puzzle input program."""
a = <unknown>
b, c = 0, 0
while a:
b = (a % 8) ^ 1
c = a // (2**b)
b = (b ^ 5) ^ c
a = a // (2**3)
print(b % 8)
Some clarification here:
- the value is octagonal. 1-8 is the key.
- The value of reg a is _high_. It is not meant to
be brute forced.
The idea, which is not originally mine, is to go
from right to left. This code can be used to try
out some patterns:
while True:
python_version(input("Provide A:"))
Here, it was apparent a=4 gives the last digit of
my puzzle input. a=37 (4 * 8 + 3) gives the last
2 digits. a=222 (37 * 8 + 6) gives the last 3
digits, and so on.
Knowing the program could be reconstructed like
this, the first code halted at wrong values. Turns
out some steps give more than 1 possible scenario.
The code was therefore in need of a queue.
|
||
|---|---|---|
| .. | ||
| output | ||
| aoc.py | ||
| README.md | ||
Advent of Code 2024
Solutions for #aoc2024 in Python 3 (3.12.7).
Programming setup:
- Lenovo Thinkpad X260
- Arch Linux with Hyprland
- Zed editor (Ruff, Pyright)
- Firefox
- Alacritty
Help scripts
Display all solved puzzles:
python aoc.py
To bootstrap a new puzzle (creates input/<day_no>.txt and output/day_<day_no>.py):
python aoc.py <day_no> new
Manually copy the puzzle input from https://adventofcode.com and paste it in input/<day_no>.txt
to start coding.
wl-paste > input/<day_no>.txt
Solve separate puzzle (replace XX with the puzzle number):
python -m output.day_XX
Solve separate puzzle using stdin (replace XX with the puzzle number):
wl-paste | python -m output.day_XX
cat tmpfile | python -m output.day_XX
Execute separate puzzle on file save (replace XX with the puzzle number):
ls output/*.py | entr -c -s 'wlpaste | python -m output.day_XX'
ls output/*.py | entr -c -s 'cat tmpfile | python -m output.day_XX'
ls output/*.py | entr -c -r python -m output.day_XX
(requires entr and wl-paste, Mac users can instead use pbpaste. If you
prefer X at Linux, use xclip -selection clipboard -o).
To lint files:
ls output/*.py | entr -r -c flake8 output --ignore=E741,E501,E203