36 lines
964 B
Python
36 lines
964 B
Python
|
#!/usr/bin/env python
|
||
|
# -*- encoding: utf-8; py-indent-offset: 4 -*-
|
||
|
|
||
|
# Author: Sebastian Mark
|
||
|
# CC-BY-SA (https://creativecommons.org/licenses/by-sa/4.0/deed.de)
|
||
|
|
||
|
# pylint: disable=missing-module-docstring,missing-function-docstring,consider-using-f-string
|
||
|
|
||
|
|
||
|
def readinput():
|
||
|
cards = {}
|
||
|
with open("input", "r", encoding="utf-8") as file:
|
||
|
i = 1
|
||
|
for line in file.readlines():
|
||
|
line = line.split(":")[1]
|
||
|
winners = line.strip("\n").split("|")[0].split()
|
||
|
mine = line.strip("\n").split("|")[1].split()
|
||
|
cards[i] = {"winners": winners, "mine": mine}
|
||
|
i += 1
|
||
|
return cards
|
||
|
|
||
|
|
||
|
def main():
|
||
|
cards = readinput()
|
||
|
|
||
|
# part 1
|
||
|
win_total = 0
|
||
|
for _, numbers in cards.items():
|
||
|
cardwin = len(set(numbers["winners"]) & set(numbers["mine"]))
|
||
|
win_total += int(2 ** (cardwin - 1))
|
||
|
print("Scratchpad worth %d points" % win_total)
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
main()
|