32 lines
805 B
Python
32 lines
805 B
Python
|
#!/usr/bin/env python
|
||
|
# 2023 - Advent Of Code 4
|
||
|
|
||
|
# file = 'input_example.txt'
|
||
|
file = 'input.txt'
|
||
|
|
||
|
|
||
|
accum = 0
|
||
|
# pylint: disable=consider-using-with
|
||
|
input_lines = [line.strip('\n') for line in open(file, encoding="utf-8")]
|
||
|
|
||
|
for line in input_lines:
|
||
|
card = line.split(':')
|
||
|
card_num = int(card[0][4:])
|
||
|
winning, got = card[1].split('|')
|
||
|
winning_num = [x for x in winning.split(' ') if x != '']
|
||
|
# print(f'{winning_num}')
|
||
|
got_num = [x for x in got.split(' ') if x != '']
|
||
|
# print(f'{got_num}')
|
||
|
multiply = 1
|
||
|
card_score = 0
|
||
|
for num in got_num:
|
||
|
if num in winning_num:
|
||
|
if card_score == 0:
|
||
|
card_score = 1
|
||
|
else:
|
||
|
card_score *= 2
|
||
|
print(f'{card_num}: {card_score}')
|
||
|
accum += card_score
|
||
|
|
||
|
print(f"sum: {accum}")
|