Compare commits
2 Commits
860884e5b2
...
e7c152d964
Author | SHA1 | Date |
---|---|---|
kwout | e7c152d964 | 11 months ago |
kwout | 681a186337 | 11 months ago |
1 changed files with 19 additions and 0 deletions
@ -0,0 +1,19 @@ |
|||||||
|
lines = [[int(m[0][-1]), 1, [[int(o) for o in n.split(" ") if o!= ""] for n in m[1].split(" | ")]] for m in [l.split(": ") for l in open("input.txt", "r").read().splitlines()]] |
||||||
|
#structure: [[id, #ofcopies, [[winning numbers], [card numbers]]]] |
||||||
|
|
||||||
|
summa = 0 |
||||||
|
|
||||||
|
for i in range(len(lines)): |
||||||
|
hits = len(set(lines[i][2][0]).intersection(lines[i][2][1])) |
||||||
|
summa += pow(2, hits-1) if hits > 0 else 0 |
||||||
|
for j in range(hits): |
||||||
|
lines[i+j+1][1] += lines[i][1] |
||||||
|
|
||||||
|
|
||||||
|
summa2 = sum([l[1] for l in lines]) |
||||||
|
|
||||||
|
print(summa) |
||||||
|
print(summa2) |
||||||
|
|
||||||
|
#cursed one line solution to part 1 |
||||||
|
#print(sum([int(pow(2, len(set(l[1][0]).intersection(l[1][1]))-1)) for l in [(int(m[0][-1]), [[int(o) for o in n.split(" ") if o!= ""] for n in m[1].split(" | ")]) for m in [l.split(": ") for l in open("input.txt", "r").read().splitlines()]]])) |
Loading…
Reference in new issue