add 2023/day4.1
This commit is contained in:
parent
51f2e7a4fd
commit
4c9b296e55
1 changed files with 35 additions and 0 deletions
35
2023/04/main.py
Normal file
35
2023/04/main.py
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
#!/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()
|
Loading…
Reference in a new issue