-
Notifications
You must be signed in to change notification settings - Fork 0
/
16.py
41 lines (34 loc) · 1.33 KB
/
16.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from util import readinput, vector, subsequences
TAPE_DATA = [('children', 3), ('cats', 7), ('samoyeds', 2), ('pomeranians', 3),
('akitas', 0), ('vizslas', 0), ('goldfish', 5), ('trees', 3),
('cars', 2), ('perfumes', 1)]
def valid():
for line in readinput(16):
sue = vector(line.replace(':', '').replace(',', ''))
sue_props = subsequences(sue, 2)[::2]
if all([prop in TAPE_DATA for prop in sue_props[1:]]):
yield sue_props[0][1]
def validEncabulator():
for line in readinput(16):
sue = vector(line.replace(':', '').replace(',', ''))
sue_props = subsequences(sue, 2)[::2]
for key, val in sue_props[1:]:
if key == 'cats':
if not val > TAPE_DATA[1][1]:
break
elif key == 'trees':
if not val > TAPE_DATA[7][1]:
break
elif key == 'pomeranians':
if not val < TAPE_DATA[3][1]:
break
elif key == 'goldfish':
if not val < TAPE_DATA[6][1]:
break
elif (key, val) not in TAPE_DATA:
break
sue_props.remove((key, val))
if len(sue_props) == 1:
yield sue_props[0][1]
print(next(valid()))
print(next(validEncabulator()))