Solve 2015 days 11-18.
This commit is contained in:
48
2015/d16.py
Normal file
48
2015/d16.py
Normal file
@@ -0,0 +1,48 @@
|
||||
import re
|
||||
data = open(0).read().strip()
|
||||
|
||||
target = {
|
||||
"children": 3,
|
||||
"cats": 7,
|
||||
"samoyeds": 2,
|
||||
"pomeranians": 3,
|
||||
"akitas": 0,
|
||||
"vizslas": 0,
|
||||
"goldfish": 5,
|
||||
"trees": 3,
|
||||
"cars": 2,
|
||||
"perfumes": 1,
|
||||
}
|
||||
|
||||
part_1 = False
|
||||
for i, line in enumerate(data.splitlines()):
|
||||
_, r = re.split(r"\d+: ", line)
|
||||
d = {"index": i + 1}
|
||||
kvs = r.split(", ")
|
||||
for kv in kvs:
|
||||
key, val = kv.split(": ")
|
||||
val = int(val)
|
||||
d[key] = val
|
||||
|
||||
if part_1:
|
||||
for k, v in d.items():
|
||||
if k in target and target[k] != v:
|
||||
break
|
||||
else:
|
||||
print(d['index'])
|
||||
else:
|
||||
for k, v in d.items():
|
||||
if k in target and (k == "cats" or k == "trees"):
|
||||
if v > target[k]:
|
||||
continue
|
||||
else:
|
||||
break
|
||||
elif k in target and (k == "pomeranians" or k == "goldfish"):
|
||||
if v < target[k]:
|
||||
continue
|
||||
else:
|
||||
break
|
||||
elif k in target and target[k] != v:
|
||||
break
|
||||
else:
|
||||
print(d['index'])
|
||||
Reference in New Issue
Block a user