Skip to content

Instantly share code, notes, and snippets.

@kaskajp
Last active December 2, 2023 13:41
Show Gist options
  • Save kaskajp/ffd0674b183d5c8c6fd2fe95d6dda0b0 to your computer and use it in GitHub Desktop.
Save kaskajp/ffd0674b183d5c8c6fd2fe95d6dda0b0 to your computer and use it in GitHub Desktop.

Revisions

  1. kaskajp renamed this gist Dec 2, 2023. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. kaskajp created this gist Dec 2, 2023.
    38 changes: 38 additions & 0 deletions aoc2023-1.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    max_red = 12
    max_green = 13
    max_blue = 14

    game_id_sum = 0

    with open('input.txt', 'r') as file:
    for line in file:
    sets = line.split(';')
    game_id = sets[0].split(':')[0].split(' ')[1]
    for set in sets:
    if ':' in set:
    set = set[set.index(':')+1:]

    set_colors = set.split(',')
    color_results_ok = True
    for color_result in set_colors:
    split_color_result = color_result.split(' ')
    set_number = int(split_color_result[1].strip())
    set_color = split_color_result[2].strip()
    if set_color == 'red' and set_number > max_red:
    color_results_ok = False
    break
    if set_color == 'green' and set_number > max_green:
    color_results_ok = False
    break
    if set_color == 'blue' and set_number > max_blue:
    color_results_ok = False
    break

    if color_results_ok == False:
    break

    if color_results_ok:
    game_id_sum += int(game_id)
    continue

    print(game_id_sum)