day 4
parent
5b2c2df628
commit
e199c391c5
|
|
@ -0,0 +1,35 @@
|
|||
from io import open
|
||||
|
||||
# We open the txt document containing the games
|
||||
input=open('input.txt','r')
|
||||
# We read the text inside distinguishing by lines
|
||||
lines = input.readlines()
|
||||
# Close the txt file to be able to work on the text without having the file open.
|
||||
input.close()
|
||||
del(input)
|
||||
|
||||
games_id=[] # number of the game
|
||||
wining_numbers=[] # Collect of winning numbers
|
||||
game_numbers=[] # Game numbers of the scratchcards
|
||||
for line in lines:
|
||||
game=line.replace("Card ","").split(":")
|
||||
games_id.append(int(game[0].strip()))
|
||||
numbers=game[1]
|
||||
game=numbers.split("|")
|
||||
wining_numbers.append(list(map(int,game[0].strip().split())))
|
||||
game_numbers.append(list(map(int,game[1].strip().split())))
|
||||
|
||||
# We check that the winning numbers are on the scratchcard numbers and accumulate the points.
|
||||
points=[]
|
||||
for game in games_id:
|
||||
points.append(0)
|
||||
for number in wining_numbers[game-1]:
|
||||
if number in game_numbers[game-1] and points[game-1]>=1:
|
||||
points[game-1]=points[game-1]*2
|
||||
elif number in game_numbers[game-1]:
|
||||
points[game-1]+=1
|
||||
|
||||
print(sum(points))
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue