working through day 3

This commit is contained in:
Jake Pullen
2023-12-02 15:26:52 +00:00
parent c83a55e79d
commit c2d362c6b3
73 changed files with 107 additions and 196 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_10\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_10\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_10\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_10\input.txt', 'r') as file:
input = file.read()
print(input)
-6
View File
@@ -1,6 +0,0 @@
import os
with open('advent_of_code_2023\day_10\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_11\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_11\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_11\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_11\input.txt', 'r') as file:
input = file.read()
print(input)
-6
View File
@@ -1,6 +0,0 @@
import os
with open('advent_of_code_2023\day_11\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_12\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_12\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_12\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_12\input.txt', 'r') as file:
input = file.read()
print(input)
-6
View File
@@ -1,6 +0,0 @@
import os
with open('advent_of_code_2023\day_12\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_13\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_13\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_13\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_13\input.txt', 'r') as file:
input = file.read()
print(input)
-6
View File
@@ -1,6 +0,0 @@
import os
with open('advent_of_code_2023\day_13\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_14\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_14\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_14\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_14\input.txt', 'r') as file:
input = file.read()
print(input)
-6
View File
@@ -1,6 +0,0 @@
import os
with open('advent_of_code_2023\day_14\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_15\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_15\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_15\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_15\input.txt', 'r') as file:
input = file.read()
print(input)
-6
View File
@@ -1,6 +0,0 @@
import os
with open('advent_of_code_2023\day_15\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_16\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_16\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_16\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_16\input.txt', 'r') as file:
input = file.read()
print(input)
-6
View File
@@ -1,6 +0,0 @@
import os
with open('advent_of_code_2023\day_16\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_17\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_17\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_17\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_17\input.txt', 'r') as file:
input = file.read()
print(input)
-6
View File
@@ -1,6 +0,0 @@
import os
with open('advent_of_code_2023\day_17\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_18\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_18\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_18\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_18\input.txt', 'r') as file:
input = file.read()
print(input)
-6
View File
@@ -1,6 +0,0 @@
import os
with open('advent_of_code_2023\day_18\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_19\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_19\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_19\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_19\input.txt', 'r') as file:
input = file.read()
print(input)
-6
View File
@@ -1,6 +0,0 @@
import os
with open('advent_of_code_2023\day_19\input.txt', 'r') as file:
input = file.read()
print(input)
+58 -4
View File
@@ -1,6 +1,60 @@
import os
# with open('advent_of_code_2023\day_2\input.txt', 'r') as file:
# input = file.read()
with open('advent_of_code_2023\day_2\input.txt', 'r') as file:
input = file.read()
# print(input)
test_input = '''Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green'''
print(input)
amount_of_cubes = '12 red, 13 green, 14 blue'
amount_of_cubes = amount_of_cubes.split(', ')
# create a dictionary to store the amount of cubes
amount_of_cubes_dict = {}
for cube in amount_of_cubes:
# split the string into the amount and the colour
# first 2 characters are the amount
cube = [int(cube[:2]), cube[3:]]
amount_of_cubes_dict[cube[1]] = cube[0]
print(f'control: {amount_of_cubes_dict}')
def check_round(round_dict):
if 'red' in round_dict and not round_dict['red']:
# check blue and green
if round_dict['blue'] > amount_of_cubes_dict['blue'] or round_dict['green'] > amount_of_cubes_dict['green']:
print('round', round_counter, 'is invalid')
return False
if 'green' in round_dict and not round_dict['green']:
# check blue and red
if round_dict['blue'] > amount_of_cubes_dict['blue'] or round_dict['red'] > amount_of_cubes_dict['red']:
print('round', round_counter, 'is invalid')
return False
if 'blue' in round_dict and not round_dict['blue']:
# check red and green
if round_dict['red'] > amount_of_cubes_dict['red'] or round_dict['green'] > amount_of_cubes_dict['green']:
print('round', round_counter, 'is invalid')
return False
else:
print('round', round_counter, 'is valid')
return True
# break out each game to check if any of the games are valid
games = test_input.split('\n')
game_counter = 0
for game in games:
game_counter += 1
game = game.split(': ')[1]
print('game', game_counter)
round_counter = 0
rounds = game.split('; ')
for round in rounds:
round_counter += 1
round = round.split(', ')
round_dict = {}
for cube in round:
cube = [int(cube[:2]), cube[2:]]
cube[1] = cube[1].replace(' ', '')
round_dict[cube[1]] = cube[0]
print(round_dict)
check_round(round_dict)
+2 -1
View File
@@ -12,12 +12,13 @@ To get information, once a bag has been loaded with cubes, the Elf will reach in
You play several games and record the information from each game (your puzzle input). Each game is listed with its ID number (like the 11 in Game 11: ...) followed by a semicolon-separated list of subsets of cubes that were revealed from the bag (like 3 red, 5 green, 4 blue).
For example, the record of a few games might look like this:
```
Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green
```
In game 1, three sets of cubes are revealed from the bag (and then put back again). The first set is 3 blue cubes and 4 red cubes; the second set is 1 red cube, 2 green cubes, and 6 blue cubes; the third set is only 2 green cubes.
The Elf would first like to know which games would have been possible if the bag contained only 12 red cubes, 13 green cubes, and 14 blue cubes?
-6
View File
@@ -1,6 +0,0 @@
import os
with open('advent_of_code_2023\day_2\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_20\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_20\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_20\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_20\input.txt', 'r') as file:
input = file.read()
print(input)
-6
View File
@@ -1,6 +0,0 @@
import os
with open('advent_of_code_2023\day_20\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_21\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_21\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_21\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_21\input.txt', 'r') as file:
input = file.read()
print(input)
-6
View File
@@ -1,6 +0,0 @@
import os
with open('advent_of_code_2023\day_21\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_22\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_22\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_22\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_22\input.txt', 'r') as file:
input = file.read()
print(input)
-6
View File
@@ -1,6 +0,0 @@
import os
with open('advent_of_code_2023\day_22\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_23\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_23\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_23\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_23\input.txt', 'r') as file:
input = file.read()
print(input)
-6
View File
@@ -1,6 +0,0 @@
import os
with open('advent_of_code_2023\day_23\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_24\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_24\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_24\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_24\input.txt', 'r') as file:
input = file.read()
print(input)
-6
View File
@@ -1,6 +0,0 @@
import os
with open('advent_of_code_2023\day_24\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_25\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_25\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_25\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_25\input.txt', 'r') as file:
input = file.read()
print(input)
-6
View File
@@ -1,6 +0,0 @@
import os
with open('advent_of_code_2023\day_25\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_3\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_3\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_3\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_3\input.txt', 'r') as file:
input = file.read()
print(input)
-6
View File
@@ -1,6 +0,0 @@
import os
with open('advent_of_code_2023\day_3\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_4\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_4\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_4\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_4\input.txt', 'r') as file:
input = file.read()
print(input)
-6
View File
@@ -1,6 +0,0 @@
import os
with open('advent_of_code_2023\day_4\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_5\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_5\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_5\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_5\input.txt', 'r') as file:
input = file.read()
print(input)
-6
View File
@@ -1,6 +0,0 @@
import os
with open('advent_of_code_2023\day_5\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_6\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_6\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_6\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_6\input.txt', 'r') as file:
input = file.read()
print(input)
-6
View File
@@ -1,6 +0,0 @@
import os
with open('advent_of_code_2023\day_6\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_7\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_7\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_7\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_7\input.txt', 'r') as file:
input = file.read()
print(input)
-6
View File
@@ -1,6 +0,0 @@
import os
with open('advent_of_code_2023\day_7\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_8\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_8\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_8\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_8\input.txt', 'r') as file:
input = file.read()
print(input)
-6
View File
@@ -1,6 +0,0 @@
import os
with open('advent_of_code_2023\day_8\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_9\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_9\input.txt', 'r') as file:
input = file.read()
print(input)
+1 -1
View File
@@ -1,6 +1,6 @@
import os
with open('advent_of_code_2023\day_9\input.txt', 'r') as file:
with open(r'advent_of_code\2023\day_9\input.txt', 'r') as file:
input = file.read()
print(input)
-6
View File
@@ -1,6 +0,0 @@
import os
with open('advent_of_code_2023\day_9\input.txt', 'r') as file:
input = file.read()
print(input)