Skip to content

Commit 72174b0

Browse files
committed
Added day 2018-14
1 parent c53a5c7 commit 72174b0

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

2018/14-Chocolate Charts.py

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# -------------------------------- Input data -------------------------------- #
2+
import os
3+
4+
test_data = {}
5+
6+
test = 1
7+
test_data[test] = {
8+
"input": 9,
9+
"expected": ["5158916779", "Unknown"],
10+
}
11+
test += 1
12+
test_data[test] = {
13+
"input": 5,
14+
"expected": ["0124515891", "Unknown"],
15+
}
16+
test += 1
17+
test_data[test] = {
18+
"input": 18,
19+
"expected": ["9251071085", "Unknown"],
20+
}
21+
test += 1
22+
test_data[test] = {
23+
"input": 2018,
24+
"expected": ["5941429882", "Unknown"],
25+
}
26+
27+
test += 1
28+
test_data[test] = {
29+
"input": "51589",
30+
"expected": ["Unknown", "9"],
31+
}
32+
test += 1
33+
test_data[test] = {
34+
"input": "01245",
35+
"expected": ["Unknown", "5"],
36+
}
37+
test += 1
38+
test_data[test] = {
39+
"input": "92510",
40+
"expected": ["Unknown", "18"],
41+
}
42+
test += 1
43+
test_data[test] = {
44+
"input": "59414",
45+
"expected": ["Unknown", "2018"],
46+
}
47+
48+
test = "real"
49+
input_file = os.path.join(
50+
os.path.dirname(__file__),
51+
"Inputs",
52+
os.path.basename(__file__).replace(".py", ".txt"),
53+
)
54+
test_data[test] = {
55+
"input": "633601",
56+
"expected": ["5115114101", "20310465"],
57+
}
58+
59+
# -------------------------------- Control program execution -------------------------------- #
60+
61+
case_to_test = "real"
62+
part_to_test = 2
63+
64+
# -------------------------------- Initialize some variables -------------------------------- #
65+
66+
puzzle_input = test_data[case_to_test]["input"]
67+
puzzle_expected_result = test_data[case_to_test]["expected"][part_to_test - 1]
68+
puzzle_actual_result = "Unknown"
69+
70+
71+
# -------------------------------- Actual code execution -------------------------------- #
72+
73+
elf1, elf2 = 0, 1
74+
recipes = [3, 7]
75+
76+
if part_to_test == 1:
77+
while len(recipes) < int(puzzle_input) + 10:
78+
new_score = recipes[elf1] + recipes[elf2]
79+
if new_score >= 10:
80+
recipes.append(new_score // 10)
81+
recipes.append(new_score % 10)
82+
elf1 += 1 + recipes[elf1]
83+
elf2 += 1 + recipes[elf2]
84+
elf1 %= len(recipes)
85+
elf2 %= len(recipes)
86+
87+
puzzle_actual_result = "".join(map(str, recipes[puzzle_input : puzzle_input + 10]))
88+
89+
90+
else:
91+
recipes = "37"
92+
puzzle_input = str(puzzle_input)
93+
while puzzle_input not in recipes[-10:]:
94+
e1, e2 = int(recipes[elf1]), int(recipes[elf2])
95+
new_score = e1 + e2
96+
if new_score >= 10:
97+
recipes += str(new_score // 10)
98+
recipes += str(new_score % 10)
99+
elf1 += 1 + e1
100+
elf2 += 1 + e2
101+
elf1 %= len(recipes)
102+
elf2 %= len(recipes)
103+
104+
puzzle_actual_result = recipes.find(puzzle_input)
105+
106+
107+
# -------------------------------- Outputs / results -------------------------------- #
108+
109+
print("Expected result : " + str(puzzle_expected_result))
110+
print("Actual result : " + str(puzzle_actual_result))

0 commit comments

Comments
 (0)