Advent_of_Code/2023/02/main.py

28 lines
541 B
Python
Raw Normal View History

2023-12-02 17:20:02 +00:00
#! Part 1
file = open("input.txt").readlines()
sum = 0
for line in range(len(file)):
game = file[line].split(";")
possible = True
for set in game:
red_pos = set.find(" r")
green_pos = set.find(" g")
blue_pos = set.find(" b")
positions = [red_pos, green_pos, blue_pos]
vals = [0, 0, 0]
for pos in range(len(positions)):
if positions[pos] != -1:
vals[pos] = int(set[positions[pos]-2:positions[pos]])
if vals[0] > 12 or vals[1] > 13 or vals[2] > 14:
possible = False
if possible:
sum += line+1
print(sum)