advent-of-code/2015-python/solutions/day_23.py
Anders Englöf Ytterström 5a5e843129
2015, day 16-25 (first completed calendar!) (#11)
* Solve 2015:16 "Aunt Sue"

* Make 2023:08 future compatible

Code used to work with another version of python.

* Solve 2015:17 "No such Thing as Too much"

* Solve 2015:18 "Like a GIF For Your Yard"

Also solve 2015:06 just in case, was just a ref
in the end.

* Solve 2015:19 "Medicine for Rudolph"

* Solve 2015:20 "Infinite Elves and Infinite Houses"

* Solve 2023:21 "RPG Simulator 20XX"

* Solve 2015:22 "Wizard Simulator 20XX"

* Solve 2015:23 "Opening the Turing Lock"

* Solve 2015:25 "Let it Snow"

Wrote p2rc and rc2p just for academic purposes.
Puzzles could be solved anyway.

* Solve 2015:24 "Hangs in the Balance"

---------

Co-authored-by: Anders Englöf Ytterström <anders@playmaker.ai>
2023-12-19 14:24:28 +01:00

65 lines
1.5 KiB
Python

from solutions import BaseSolution
class Solution(BaseSolution):
input_file = "23.txt"
def __str__(self):
return "Day 23: Opening the Turing Lock"
def _solve(self, pi):
p12 = []
for a in [0, 1]:
m = {
"a": a,
"b": 0,
}
p = [l.split() for l in pi.splitlines()]
i = 0
while i < len(p):
v, rv, *a = p[i]
rv = rv.split(",")[0]
match v:
case "hlf":
m[rv] //= 2
i += 1
case "tpl":
m[rv] *= 3
i += 1
case "inc":
m[rv] += 1
i += 1
case "jmp":
i += int(rv)
case "jie":
i += int(a[0]) if int(m[rv]) % 2 == 0 else 1
case "jio":
i += int(a[0]) if int(m[rv]) == 1 else 1
p12.append(m["b"])
return p12
def solve(self, pi):
o = self._solve(pi)
return o[0]
def solve_again(self, pi):
o = self._solve(pi)
return o[1]
def parse_input(self, data):
return data.strip()
if __name__ == "__main__":
solution = Solution()
solution.show_results()
dummy = """
inc a
jio a, +2
tpl a
inc a
""".strip()
# solution.solve(dummy)
# solution.solve_again(dummy)