|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- from helpers import Helper
-
- helper = Helper(debug=True)
- load_input = helper.load_input
- debug = helper.debug
-
- class Card:
- """ A single scratch-off card for AOC 2023 day 4. """
-
- def __init__(self, input_line):
- card_id, numbers = input_line.split(": ")
- winning, have = numbers.split(" | ")
-
- self.idnum = card_id.split()[1]
- self.winning = [int(n) for n in winning.split()]
- self.have = [int(n) for n in have.split()]
-
- @property
- def num_winners(self) -> int:
- winners = 0
- for number in self.have:
- if number in self.winning:
- winners += 1
-
- return winners
-
- @property
- def score(self) -> int:
- return 2**(self.num_winners-1) if self.num_winners > 0 else 0
-
- def main():
- lines = load_input(4)
- cards = []
-
- for line in lines:
- cards.append(Card(input_line=line))
-
- total_score = 0
- for card in cards:
- total_score += card.score
-
- print(f"Total score: {total_score}")
-
-
- if __name__ == "__main__":
- main()
|