day23 - for p2 I'm guessing what number is changing between inputs
This commit is contained in:
parent
6a8040d4d9
commit
a44bd51f68
69
day23.py
Normal file
69
day23.py
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
|
from tools.aoc import AOCDay
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from tools.math import get_factors
|
||||||
|
|
||||||
|
|
||||||
|
class Day(AOCDay):
|
||||||
|
inputs = [
|
||||||
|
[
|
||||||
|
(4225, "input23")
|
||||||
|
],
|
||||||
|
[
|
||||||
|
(905, "input23")
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
def get_commands(self) -> list:
|
||||||
|
return [x.split(" ") for x in self.getInput()]
|
||||||
|
|
||||||
|
def part1(self) -> Any:
|
||||||
|
register = defaultdict(int)
|
||||||
|
index = 0
|
||||||
|
commands = self.get_commands()
|
||||||
|
mul_count = 0
|
||||||
|
while 0 <= index < len(commands):
|
||||||
|
cmd = commands[index]
|
||||||
|
|
||||||
|
try:
|
||||||
|
value = int(cmd[2])
|
||||||
|
except ValueError:
|
||||||
|
value = register[cmd[2]]
|
||||||
|
|
||||||
|
match cmd[0]:
|
||||||
|
case "set":
|
||||||
|
register[cmd[1]] = value
|
||||||
|
case "sub":
|
||||||
|
register[cmd[1]] -= value
|
||||||
|
case "mul":
|
||||||
|
mul_count += 1
|
||||||
|
register[cmd[1]] *= value
|
||||||
|
case "jnz":
|
||||||
|
try:
|
||||||
|
jumper = int(cmd[1])
|
||||||
|
except ValueError:
|
||||||
|
jumper = register[cmd[1]]
|
||||||
|
if jumper != 0:
|
||||||
|
index += value - 1
|
||||||
|
|
||||||
|
index += 1
|
||||||
|
|
||||||
|
return mul_count
|
||||||
|
|
||||||
|
def part2(self) -> Any:
|
||||||
|
b = int(self.getInput()[0].split(" ")[2]) * 100 + 100000
|
||||||
|
c = b + 17000
|
||||||
|
h = 0
|
||||||
|
while b <= c:
|
||||||
|
if len(get_factors(b)) > 2:
|
||||||
|
h += 1
|
||||||
|
b += 17
|
||||||
|
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
day = Day(2017, 23)
|
||||||
|
day.run(verbose=True)
|
||||||
32
inputs/input23
Normal file
32
inputs/input23
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
set b 67
|
||||||
|
set c b
|
||||||
|
jnz a 2
|
||||||
|
jnz 1 5
|
||||||
|
mul b 100
|
||||||
|
sub b -100000
|
||||||
|
set c b
|
||||||
|
sub c -17000
|
||||||
|
set f 1
|
||||||
|
set d 2
|
||||||
|
set e 2
|
||||||
|
set g d
|
||||||
|
mul g e
|
||||||
|
sub g b
|
||||||
|
jnz g 2
|
||||||
|
set f 0
|
||||||
|
sub e -1
|
||||||
|
set g e
|
||||||
|
sub g b
|
||||||
|
jnz g -8
|
||||||
|
sub d -1
|
||||||
|
set g d
|
||||||
|
sub g b
|
||||||
|
jnz g -13
|
||||||
|
jnz f 2
|
||||||
|
sub h -1
|
||||||
|
set g b
|
||||||
|
sub g c
|
||||||
|
jnz g 2
|
||||||
|
jnz 1 3
|
||||||
|
sub b -17
|
||||||
|
jnz 1 -23
|
||||||
Loading…
Reference in New Issue
Block a user