Skip to content

Commit da3113b

Browse files
authored
Merge pull request github#2 from rcruz63/feature/dia2
Feature/dia2
2 parents 75dedd0 + 8ef1a5d commit da3113b

10 files changed

Lines changed: 471 additions & 0 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,5 @@ cython_debug/
158158
# and can be added to the global gitignore or merged into this file. For a more nuclear
159159
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160160
#.idea/
161+
162+
out*.txt

README_DIA2_EN.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Day 2: Cube Conundrum ---
2+
You're launched high into the atmosphere! The apex of your trajectory just barely reaches the surface of a large island floating in the sky. You gently land in a fluffy pile of leaves. It's quite cold, but you don't see much snow. An Elf runs over to greet you.
3+
4+
The Elf explains that you've arrived at Snow Island and apologizes for the lack of snow. He'll be happy to explain the situation, but it's a bit of a walk, so you have some time. They don't get many visitors up here; would you like to play a game in the meantime?
5+
6+
As you walk, the Elf shows you a small bag and some cubes which are either red, green, or blue. Each time you play this game, he will hide a secret number of cubes of each color in the bag, and your goal is to figure out information about the number of cubes.
7+
8+
To get information, once a bag has been loaded with cubes, the Elf will reach into the bag, grab a handful of random cubes, show them to you, and then put them back in the bag. He'll do this a few times per game.
9+
10+
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).
11+
12+
For example, the record of a few games might look like this:
13+
14+
Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
15+
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
16+
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
17+
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
18+
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green
19+
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.
20+
21+
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?
22+
23+
In the example above, games 1, 2, and 5 would have been possible if the bag had been loaded with that configuration. However, game 3 would have been impossible because at one point the Elf showed you 20 red cubes at once; similarly, game 4 would also have been impossible because the Elf showed you 15 blue cubes at once. If you add up the IDs of the games that would have been possible, you get 8.
24+
25+
Determine which games would have been possible if the bag had been loaded with only 12 red cubes, 13 green cubes, and 14 blue cubes. What is the sum of the IDs of those games?
26+
27+
## --- Part Two ---
28+
The Elf says they've stopped producing snow because they aren't getting any water! He isn't sure why the water stopped; however, he can show you how to get to the water source to check it out for yourself. It's just up ahead!
29+
30+
As you continue your walk, the Elf poses a second question: in each game you played, what is the fewest number of cubes of each color that could have been in the bag to make the game possible?
31+
32+
Again consider the example games from earlier:
33+
34+
Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
35+
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
36+
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
37+
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
38+
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green
39+
In game 1, the game could have been played with as few as 4 red, 2 green, and 6 blue cubes. If any color had even one fewer cube, the game would have been impossible.
40+
Game 2 could have been played with a minimum of 1 red, 3 green, and 4 blue cubes.
41+
Game 3 must have been played with at least 20 red, 13 green, and 6 blue cubes.
42+
Game 4 required at least 14 red, 3 green, and 15 blue cubes.
43+
Game 5 needed no fewer than 6 red, 3 green, and 2 blue cubes in the bag.
44+
The power of a set of cubes is equal to the numbers of red, green, and blue cubes multiplied together. The power of the minimum set of cubes in game 1 is 48. In games 2-5 it was 12, 1560, 630, and 36, respectively. Adding up these five powers produces the sum 2286.
45+
46+
For each game, find the minimum set of cubes that must have been present. What is the sum of the power of these sets?

README_DIA2_ES.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Día 2: Enigma del Cubo ---
2+
¡Eres lanzado alto en la atmósfera! El punto más alto de tu trayectoria apenas roza la superficie de una gran isla flotando en el cielo. Aterrizas suavemente en una mullida pila de hojas. Hace bastante frío, pero no ves mucha nieve. Un elfo corre hacia ti para saludarte.
3+
4+
El elfo explica que has llegado a la Isla de la Nieve y se disculpa por la falta de nieve. Estará encantado de explicarte la situación, pero es un poco lejos, así que tienes algo de tiempo. No reciben muchos visitantes aquí arriba; ¿te gustaría jugar a un juego mientras tanto?
5+
6+
Mientras caminas, el elfo te muestra una bolsa pequeña y algunos cubos que son rojos, verdes o azules. Cada vez que juegas este juego, él esconde una cantidad secreta de cubos de cada color en la bolsa, y tu objetivo es descubrir información sobre la cantidad de cubos.
7+
8+
Para obtener información, una vez que una bolsa ha sido cargada con cubos, el elfo meterá la mano en la bolsa, cogerá un puñado de cubos al azar, te los mostrará y luego los devolverá a la bolsa. Él hará esto varias veces en cada juego.
9+
10+
Juegas varias partidas y registras la información de cada juego (tu entrada de puzles). Cada juego está listado con su número de identificación (como el 11 en Juego 11: ...) seguido de una lista separada por punto y coma de subconjuntos de cubos que fueron revelados de la bolsa (como 3 azules, 5 verdes, 4 azules).
11+
12+
Por ejemplo, el registro de algunos juegos podría verse así:
13+
14+
Juego 1: 3 azules, 4 rojos; 1 rojo, 2 verdes, 6 azules; 2 verdes
15+
Juego 2: 1 azul, 2 verdes; 3 verdes, 4 azules, 1 rojo; 1 verde, 1 azul
16+
Juego 3: 8 verdes, 6 azules, 20 rojos; 5 azules, 4 rojos, 13 verdes; 5 verdes, 1 rojo
17+
Juego 4: 1 verde, 3 rojos, 6 azules; 3 verdes, 6 rojos; 3 verdes, 15 azules, 14 rojos
18+
Juego 5: 6 rojos, 1 azul, 3 verdes; 2 azules, 1 rojo, 2 verdes
19+
En el juego 1, se revelan tres conjuntos de cubos de la bolsa (y luego se vuelven a poner). El primer conjunto es de 3 cubos azules y 4 cubos rojos; el segundo conjunto es de 1 cubo rojo, 2 cubos verdes y 6 cubos azules; el tercer conjunto es solo de 2 cubos verdes.
20+
21+
El elfo quiere saber primero qué juegos habrían sido posibles si la bolsa solo contuviera 12 cubos rojos, 13 cubos verdes y 14 cubos azules.
22+
23+
En el ejemplo anterior, los juegos 1, 2 y 5 habrían sido posibles si la bolsa hubiera estado cargada con esa configuración. Sin embargo, el juego 3 habría sido imposible porque en un momento el elfo te mostró 20 cubos rojos a la vez; de manera similar, el juego 4 también habría sido imposible porque el elfo te mostró 15 cubos azules a la vez. Si sumas los ID de los juegos que habrían sido posibles, obtienes 8.
24+
25+
Determina qué juegos habrían sido posibles si la bolsa hubiera sido cargada solo con 12 cubos rojos, 13 cubos verdes y 14 cubos azules. ¿Cuál es la suma de los ID de esos juegos?
26+
27+
## ¡Claro, puedo ayudarte! Aquí está la traducción al español:
28+
29+
--- Parte Dos ---
30+
¡El elfo dice que han dejado de producir nieve porque no están recibiendo agua! No está seguro de por qué se detuvo el agua; sin embargo, puede mostrarte cómo llegar a la fuente de agua para que lo compruebes por ti mismo. ¡Está justo ahí adelante!
31+
32+
Mientras continúas tu caminata, el elfo plantea una segunda pregunta: en cada juego que jugaste, ¿cuál es la menor cantidad de cubos de cada color que podría haber estado en la bolsa para hacer posible el juego?
33+
34+
Considera nuevamente los juegos de ejemplo mencionados anteriormente:
35+
36+
Juego 1: 3 azules, 4 rojos; 1 rojo, 2 verdes, 6 azules; 2 verdes
37+
Juego 2: 1 azul, 2 verdes; 3 verdes, 4 azules, 1 rojo; 1 verde, 1 azul
38+
Juego 3: 8 verdes, 6 azules, 20 rojos; 5 azules, 4 rojos, 13 verdes; 5 verdes, 1 rojo
39+
Juego 4: 1 verde, 3 rojos, 6 azules; 3 verdes, 6 rojos; 3 verdes, 15 azules, 14 rojos
40+
Juego 5: 6 rojos, 1 azul, 3 verdes; 2 azules, 1 rojo, 2 verdes
41+
En el juego 1, el juego podría haberse jugado con un mínimo de 4 cubos rojos, 2 verdes y 6 azules. Si algún color tuviera incluso un cubo menos, el juego habría sido imposible.
42+
El juego 2 podría haberse jugado con un mínimo de 1 rojo, 3 verdes y 4 azules.
43+
El juego 3 debe haberse jugado con al menos 20 rojos, 13 verdes y 6 azules.
44+
El juego 4 requirió al menos 14 rojos, 3 verdes y 15 azules.
45+
El juego 5 no necesitaba menos de 6 rojos, 3 verdes y 2 azules en la bolsa.
46+
El poder de un conjunto de cubos es igual al producto de los números de cubos rojos, verdes y azules. El poder del conjunto mínimo de cubos en el juego 1 es 48. En los juegos 2-5 fue 12, 1560, 630 y 36, respectivamente. Sumar estos cinco poderes produce la suma 2286.
47+
48+
Para cada juego, encuentra el conjunto mínimo de cubos que debe haber estado presente. ¿Cuál es la suma del poder de estos conjuntos?

adv2023/app.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""This is the main application file for the adv2023 package. """
22
from adv2023.dia1.dia1 import dia1_1, dia1_2
3+
from adv2023.dia2.dia2 import dia2_1, dia2_2
34

45

56
def run():
@@ -9,6 +10,7 @@ def run():
910
# Print the menu
1011
print("Welcome to the menu")
1112
print("1. Dia 1")
13+
print("2. Dia 2")
1214
print("Q. Exit")
1315

1416
# Ask the user for a choice
@@ -17,6 +19,9 @@ def run():
1719
if choice == "1":
1820
dia1_1("data1_1.txt")
1921
dia1_2("data1_2.txt")
22+
elif choice == "2":
23+
dia2_1("data2_1.txt", False)
24+
dia2_2("data2_2.txt", False)
2025
# If the user chooses Q, exit the loop
2126
elif choice.upper() == "Q":
2227
break

adv2023/dia2/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)