-
Notifications
You must be signed in to change notification settings - Fork 0
/
day4.1.py
38 lines (29 loc) · 987 Bytes
/
day4.1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# -*- coding: utf-8 -*-
"""
Created on Mon Dec 4 07:37:07 2023
@author: mark.patmore
"""
with open('inputs/day4.txt', 'r') as x:
total_score = 0
card_score = 0
for i in x:
winning_numbers = []
winning_string = i[i.index(':'):i.index('|')-1].split(' ')
for j in winning_string:
if j.isnumeric():
winning_numbers.append(int(j))
player_numbers = []
player_string = i[i.index('|')+1:].split(' ')
for k in player_string:
k = k.strip('\n')
if k.isnumeric():
player_numbers.append(int(k))
for l in player_numbers:
if l in winning_numbers:
if card_score == 0:
card_score = 1
else:
card_score *= 2
total_score += card_score
card_score = 0
print(total_score)