2018 Day 16 rough

This commit is contained in:
Luke Hubmayer-Werner 2018-12-16 16:29:33 +10:30
parent 217de46a5d
commit 4d583073a2
4 changed files with 8439 additions and 0 deletions

4140
2018/day16-input Normal file

File diff suppressed because it is too large Load Diff

3187
2018/day16-input1 Normal file

File diff suppressed because it is too large Load Diff

950
2018/day16-input2 Normal file
View File

@ -0,0 +1,950 @@
13 0 0 0
3 0 2 0
8 3 0 1
13 0 0 3
3 3 1 3
4 0 1 0
13 0 1 0
1 2 0 2
8 2 1 3
8 1 2 0
13 0 0 1
3 1 0 1
2 0 3 1
13 1 3 1
13 1 3 1
1 2 1 2
11 2 0 0
8 3 0 2
8 3 2 1
8 0 0 3
12 3 2 2
13 2 2 2
13 2 1 2
1 0 2 0
11 0 3 1
8 3 1 3
8 0 2 2
8 0 3 0
0 3 2 3
13 3 1 3
1 1 3 1
11 1 1 3
8 3 1 0
8 0 2 1
13 3 0 2
3 2 2 2
4 2 0 1
13 1 3 1
1 3 1 3
11 3 2 1
8 0 2 3
8 1 0 0
15 3 2 2
13 2 3 2
1 1 2 1
11 1 2 3
8 3 0 1
8 2 0 2
11 0 2 2
13 2 3 2
1 2 3 3
11 3 2 0
13 2 0 2
3 2 3 2
8 3 1 3
0 3 2 3
13 3 1 3
1 3 0 0
11 0 3 1
8 2 2 3
8 2 1 2
8 3 0 0
4 2 0 3
13 3 1 3
1 3 1 1
11 1 0 2
8 3 3 3
8 2 2 0
13 1 0 1
3 1 0 1
5 3 0 3
13 3 1 3
1 2 3 2
11 2 3 1
8 1 1 0
8 0 2 3
8 2 0 2
11 0 2 3
13 3 1 3
1 3 1 1
13 2 0 3
3 3 3 3
8 2 3 0
13 2 0 2
3 2 3 2
7 0 2 3
13 3 3 3
1 3 1 1
8 2 0 2
13 3 0 3
3 3 1 3
2 3 0 0
13 0 2 0
13 0 1 0
1 1 0 1
8 2 3 0
8 2 0 3
10 2 3 2
13 2 3 2
13 2 3 2
1 2 1 1
11 1 1 0
8 0 1 1
8 1 0 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1
8 2 0 2
8 0 0 0
8 1 1 3
8 3 0 2
13 2 1 2
1 1 2 1
11 1 0 0
8 2 0 3
8 1 1 1
13 1 0 2
3 2 3 2
2 1 3 2
13 2 2 2
1 2 0 0
8 3 2 1
8 0 0 2
5 1 3 2
13 2 3 2
1 0 2 0
11 0 2 3
8 2 2 2
8 2 1 0
8 1 3 1
2 1 0 0
13 0 1 0
1 3 0 3
11 3 0 1
8 2 1 3
13 0 0 2
3 2 1 2
8 1 1 0
1 0 0 3
13 3 3 3
1 3 1 1
8 2 0 0
8 2 3 3
13 2 0 2
3 2 0 2
9 0 3 0
13 0 3 0
1 0 1 1
11 1 3 0
8 2 2 2
8 0 3 3
8 0 1 1
15 3 2 2
13 2 3 2
1 0 2 0
11 0 2 3
8 3 2 0
13 3 0 2
3 2 2 2
6 2 0 0
13 0 1 0
1 0 3 3
11 3 3 0
8 3 3 3
8 0 3 2
8 2 2 1
5 3 1 2
13 2 3 2
13 2 1 2
1 0 2 0
11 0 0 1
8 2 0 0
8 0 0 3
8 0 0 2
10 0 3 3
13 3 1 3
1 3 1 1
11 1 2 3
8 3 3 2
8 0 1 1
8 2 1 1
13 1 1 1
13 1 1 1
1 3 1 3
11 3 1 0

162
2018/day16.py Normal file
View File

@ -0,0 +1,162 @@
with open('day16-input1', 'r') as file:
data = [l.strip('\n') for l in file]
with open('day16-input2', 'r') as file:
data2 = [l.strip('\n') for l in file]
import numpy as np
import re
numbers = [[int(s) for s in re.findall(r'-?\d+', d)] for d in data if d]
numbers2 = [[int(s) for s in re.findall(r'-?\d+', d)] for d in data2 if d]
# arr = np.array(numbers, dtype=np.int64)
registers = np.zeros(4, dtype=np.int64)
def addr(regs, opcodes):
op, a, b, c = opcodes
r = list(regs)
r[c] = regs[a] + regs[b]
return r
def addi(regs, opcodes):
op, a, b, c = opcodes
r = list(regs)
r[c] = regs[a] + b
return r
def mulr(regs, opcodes):
op, a, b, c = opcodes
r = list(regs)
r[c] = regs[a] * regs[b]
return r
def muli(regs, opcodes):
op, a, b, c = opcodes
r = list(regs)
r[c] = regs[a] * b
return r
def andr(regs, opcodes):
op, a, b, c = opcodes
r = list(regs)
r[c] = regs[a] & regs[b]
return r
def andi(regs, opcodes):
op, a, b, c = opcodes
r = list(regs)
r[c] = regs[a] & b
return r
def orr(regs, opcodes):
op, a, b, c = opcodes
r = list(regs)
r[c] = regs[a] | regs[b]
return r
def ori(regs, opcodes):
op, a, b, c = opcodes
r = list(regs)
r[c] = regs[a] | b
return r
def setr(regs, opcodes):
op, a, b, c = opcodes
r = list(regs)
r[c] = regs[a]
return r
def seti(regs, opcodes):
op, a, b, c = opcodes
r = list(regs)
r[c] = a
return r
def gtir(regs, opcodes):
op, a, b, c = opcodes
r = list(regs)
r[c] = int(bool(a > regs[b]))
return r
def gtri(regs, opcodes):
op, a, b, c = opcodes
r = list(regs)
r[c] = int(bool(regs[a] > b))
return r
def gtrr(regs, opcodes):
op, a, b, c = opcodes
r = list(regs)
r[c] = int(bool(regs[a] > regs[b]))
return r
def eqir(regs, opcodes):
op, a, b, c = opcodes
r = list(regs)
r[c] = int(bool(a == regs[b]))
return r
def eqri(regs, opcodes):
op, a, b, c = opcodes
r = list(regs)
r[c] = int(bool(regs[a] == b))
return r
def eqrr(regs, opcodes):
op, a, b, c = opcodes
r = list(regs)
r[c] = int(bool(regs[a] == regs[b]))
return r
instructions = [addr, addi, mulr, muli, andr, andi, orr, ori, setr, seti, gtir, gtri, gtrr, eqir, eqri, eqrr]
num_3_or_more = 0
instruction_codes = {}
instruction_impossibilities = {}
for before, opcodes, after in zip(numbers[::3], numbers[1::3], numbers[2::3]):
possibilities = set()
impossibilities = set()
for op in instructions:
try:
r2 = op(before, opcodes)
if r2 == after:
possibilities.add(op)
else:
impossibilities.add(op)
except:
impossibilities.add(op)
if len(possibilities) >= 3:
num_3_or_more += 1
if opcodes[0] in instruction_codes:
instruction_codes[opcodes[0]] &= possibilities
else:
instruction_codes[opcodes[0]] = set(possibilities)
if opcodes[0] in instruction_impossibilities:
instruction_impossibilities[opcodes[0]] |= impossibilities
else:
instruction_impossibilities[opcodes[0]] = set(impossibilities)
print(num_3_or_more) # Part 1
for k in instruction_codes:
instruction_codes[k] -= instruction_impossibilities[k]
while sum([len(i) for i in instruction_codes.values()]) > len(instructions):
for code, cands in instruction_codes.items():
if len(cands) == 1:
for code2 in [c for c in instruction_codes if c != code]:
instruction_codes[code2] -= cands
opcode_convert = {code: list(s)[0] for code, s in instruction_codes.items()}
regs = [0, 0, 0, 0]
for i, opcodes in enumerate(numbers2):
try:
regs = opcode_convert[opcodes[0]](regs, opcodes)
except:
print(f'Line {i}: {regs} {opcodes}')
raise
print(regs) # Part 2 is first number