Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #PART 1
- with open("input") as file:
- data = file.read().splitlines()
- d={'red':12,'green':13,'blue':14}
- sum = 0
- for line in data:
- id, games = line.split(": ")
- games = games.split("; ")
- id = int(id[5:])
- p = True
- for game in games:
- g=game.split(", ")
- for _ in g:
- n,c = _.split(" ")
- if c in d and int(n)>d.get(c):
- p=False
- break
- if (p == True):
- sum+= id
- print(sum)
- #PART 2
- from functools import reduce
- sum=0
- for line in data:
- d = {'red': [], 'green': [], 'blue': []}
- id, games = line.split(": ")
- games = games.split("; ")
- id = int(id[5:])
- for game in games:
- g=game.split(", ")
- for _ in g:
- n,c = _.split(" ")
- if c in d:
- d[c].append(int(n))
- sum+= reduce(lambda x,y:x*y,[max(d[x]) for x in d])
- print(sum)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement