-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.py
48 lines (40 loc) · 1.15 KB
/
script.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
42
43
44
45
46
47
48
import sys
import re
wrapping = {
'children': 3,
'cats': 7,
'samoyeds': 2,
'pomeranians': 3,
'akitas': 0,
'vizslas': 0,
'goldfish': 5,
'trees': 3,
'cars': 2,
'perfumes': 1,
}
def check_sue_p1(sue):
for prop, amount in sue.items():
if amount != wrapping[prop]:
return False
return True
def check_sue_p2(sue):
for prop, amount in sue.items():
if prop in ['cats', 'trees']:
if amount <= wrapping[prop]:
return False
elif prop in ['pomeranians', 'goldfish']:
if amount >= wrapping[prop]:
return False
elif wrapping[prop] != amount:
return False
return True
if __name__ == '__main__':
inputs = (line.rstrip('\n') for line in open(sys.argv[1]))
sues = {}
for i, line in enumerate(inputs):
sues[i+1] = {name: int(amount) for name, amount in map(lambda s: s.split(': '), re.sub(r'^Sue \d+: ', '', line).split(', '))}
for number, sue in sues.items():
if check_sue_p1(sue):
print('p1', number, sue)
if check_sue_p2(sue):
print('p2', number, sue)