Skip to content

Commit bbedcfd

Browse files
committed
Added day 2018-11
1 parent 7e8c5f4 commit bbedcfd

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

2018/11-Chronal Charge.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# -------------------------------- Input data -------------------------------- #
2+
import os, numpy as np
3+
4+
test_data = {}
5+
6+
test = 1
7+
test_data[test] = {"input": 18,
8+
"expected": ['Unknown', 'Unknown'],
9+
}
10+
11+
test = 'real'
12+
input_file = os.path.join(os.path.dirname(__file__), 'Inputs', os.path.basename(__file__).replace('.py', '.txt'))
13+
test_data[test] = {"input": 7165,
14+
"expected": ['(235, 20) with 31', '(237, 223, 14) with 83'],
15+
}
16+
17+
# -------------------------------- Control program execution -------------------------------- #
18+
19+
case_to_test = 'real'
20+
part_to_test = 2
21+
22+
# -------------------------------- Initialize some variables -------------------------------- #
23+
24+
puzzle_input = test_data[case_to_test]['input']
25+
puzzle_expected_result = test_data[case_to_test]['expected'][part_to_test-1]
26+
puzzle_actual_result = 'Unknown'
27+
28+
29+
# -------------------------------- Actual code execution -------------------------------- #
30+
31+
32+
if part_to_test == 1:
33+
grid_power = {(x, y): int(((((10+x)*y + puzzle_input) * (10+x)) // 100) % 10)-5 for x in range (1, 301) for y in range (1, 301)}
34+
35+
sum_power = {(x, y): sum(grid_power[x1, y1] for x1 in range (x, x+3) for y1 in range (y, y+3)) for x in range (1, 299) for y in range (1, 299)}
36+
37+
max_power = max(sum_power.values())
38+
39+
puzzle_actual_result = list(coord for coord in sum_power if sum_power[coord] == max_power)
40+
41+
42+
else:
43+
grid_power = {(x, y): int(((((10+x)*y + puzzle_input) * (10+x)) // 100) % 10)-5 for x in range (1, 301) for y in range (1, 301)}
44+
45+
max_power = 31
46+
sum_power = grid_power.copy()
47+
for size in range (2, 300):
48+
sum_power = {(x, y, size): sum(grid_power[x1, y1]
49+
for x1 in range (x, x+size)
50+
for y1 in range (y, y+size))
51+
for x in range (1, 301-size+1)
52+
for y in range (1, 301-size+1)}
53+
54+
new_max = max(sum_power.values())
55+
if new_max > max_power:
56+
max_power = new_max
57+
puzzle_actual_result = list(coord + (size,) for coord in sum_power if sum_power[coord] == max_power)
58+
59+
# Basically, let it run until it decreases multiple times
60+
print (size, new_max, list(coord for coord in sum_power if sum_power[coord] == new_max))
61+
62+
63+
64+
# -------------------------------- Outputs / results -------------------------------- #
65+
66+
print ('Expected result : ' + str(puzzle_expected_result))
67+
print ('Actual result : ' + str(puzzle_actual_result))
68+
69+
70+
71+

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy