advent-of-code/2018/day-16/01.py

37 lines
789 B
Python
Raw Normal View History

2018-12-17 14:26:43 +01:00
from ops import ops
from copy import copy
with open('input.txt', 'r') as f:
raw = f.readlines()
samples = []
i = 0
while 1:
sample = {}
if raw[i] == '\n':
break
sample['in'] = [int(x) for x in raw[i][9:-2].split(', ')]
sample['op'] = [int(x) for x in raw[i + 1].strip().split(' ')]
sample['out'] = [int(x) for x in raw[i + 2][9:-2].split(', ')]
samples.append(sample)
i += 4
print(samples)
res = 0
for sample in samples:
count = 0
num, a, b, c = sample['op']
for op in ops:
try:
if sample['out'] == op(copy(sample['in']), a, b, c):
count += 1
except:
pass
if count >= 3:
res += 1
# print(sample)
print(res)