d8
This commit is contained in:
parent
39bf998b51
commit
e3de15393a
64
day08.py
Normal file
64
day08.py
Normal file
@ -0,0 +1,64 @@
|
||||
from collections import defaultdict
|
||||
|
||||
from tools.aoc import AOCDay
|
||||
from typing import Any
|
||||
|
||||
|
||||
class Day(AOCDay):
|
||||
inputs = [
|
||||
[
|
||||
(6828, "input8")
|
||||
],
|
||||
[
|
||||
(7234, "input8")
|
||||
]
|
||||
]
|
||||
|
||||
def parse_input(self) -> (dict, int):
|
||||
max_value = 0
|
||||
register = defaultdict(int)
|
||||
for line in self.getInput():
|
||||
reg, cmd, value, _, test_reg, test_op, test_value = line.split(" ")
|
||||
value = int(value)
|
||||
test_value = int(test_value)
|
||||
test_outcome = False
|
||||
if test_op == '<':
|
||||
test_outcome = register[test_reg] < test_value
|
||||
elif test_op == '>':
|
||||
test_outcome = register[test_reg] > test_value
|
||||
elif test_op == '>=':
|
||||
test_outcome = register[test_reg] >= test_value
|
||||
elif test_op == '<=':
|
||||
test_outcome = register[test_reg] <= test_value
|
||||
elif test_op == '==':
|
||||
test_outcome = register[test_reg] == test_value
|
||||
elif test_op == '!=':
|
||||
test_outcome = register[test_reg] != test_value
|
||||
else:
|
||||
print("UNKNOWN TEST", test_op)
|
||||
|
||||
if test_outcome:
|
||||
if cmd == 'inc':
|
||||
register[reg] += value
|
||||
elif cmd == 'dec':
|
||||
register[reg] -= value
|
||||
else:
|
||||
print("UNKNOWN COMMAND", cmd)
|
||||
|
||||
if register[reg] > max_value:
|
||||
max_value = register[reg]
|
||||
|
||||
return register, max_value
|
||||
|
||||
def part1(self) -> Any:
|
||||
register, _ = self.parse_input()
|
||||
return max(register.values())
|
||||
|
||||
def part2(self) -> Any:
|
||||
_, ret = self.parse_input()
|
||||
return ret
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
day = Day(2017, 8)
|
||||
day.run(verbose=True)
|
||||
1000
inputs/input8
Normal file
1000
inputs/input8
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user