-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday10part2.py
More file actions
67 lines (51 loc) · 1.98 KB
/
Copy pathday10part2.py
File metadata and controls
67 lines (51 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# THIS IS A WIP - SOLUTION IS NOT CORRECT
import numpy as np
machines = []
light_total_presses = 0
joltage_total_presses = 0
class Machine:
def __init__(self, lights, buttons, joltage):
self.lights = lights
self.buttons = buttons
self.joltage = joltage
def button_conversion(button, lights_length):
new_button = [0] * lights_length
for number in button:
new_button[int(number)] = 1
return new_button
with open('day10input.txt', 'r') as file:
for row in file:
instruction = row.strip()
instruction = instruction.split(" ")
# Parse light indicator
light_indicator = instruction[0].translate(str.maketrans({"[" : "", "]" : "", "." : "0", "#" : "1"}))
# Parse joltage
joltage = instruction[-1].translate(str.maketrans({"{" : "", "}" : ""}))
joltage_array = joltage.split(",")
# Parse buttons
buttons = []
b = 1
while b < len(instruction) - 1:
button = instruction[b].translate(str.maketrans({"(" : "", ")" : ""}))
button = button.split(",")
buttons.append(button)
b += 1
new_machine = Machine(light_indicator, buttons, joltage_array)
machines.append(new_machine)
for machine in machines:
joltage_length = len(machine.lights)
# Joltage indicator array to compare button presses with
target_joltage = []
for joltage in machine.joltage:
target_joltage.append(int(joltage))
print(target_joltage)
# Create int array of button instructions
button_array = []
for button in machine.buttons:
button_array.append(button_conversion(button, joltage_length))
matrix = np.transpose(button_array)
print(matrix)
# Solve system of linear equations to find button presses
#solution = np.linalg.solve(matrix, target_joltage)
#print(solution)
print("Minimum Button Presses (Joltage Indicator): " + str(joltage_total_presses))