aoc

Advent of code
git clone https://codeberg.org/night0721/aoc
Log | Files | Refs

1.py (890B)


      1 games = []
      2 with open('input') as f:
      3     for line in f:
      4         splitted = line.rstrip().split(":")
      5         id = splitted[0].split(" ")[1]
      6         sets = "".join(splitted[1]).split(";")
      7         for i in sets:
      8             ok = True
      9             colors = [0, 0, 0]
     10             detail = i.strip().split(", ")
     11             for i in range(len(detail)):
     12                 count = "".join(detail[i]).split(" ")[0]
     13                 color = "".join(detail[i]).split(" ")[1]
     14                 if color == "red":
     15                     colors[0] += int(count)
     16                 elif color == "green":
     17                     colors[1] += int(count)
     18                 elif color == "blue":
     19                     colors[2] += int(count)
     20             if colors[0] > 12 or colors[1] > 13 or colors[2] > 14:
     21                 ok = False
     22                 break
     23         if ok:
     24             games.append(int(id))
     25     print(sum(games))