-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday10a.py
More file actions
35 lines (27 loc) · 775 Bytes
/
day10a.py
File metadata and controls
35 lines (27 loc) · 775 Bytes
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
import itertools
f = open('input.txt', 'r')
lines = [line.split(' ') for line in f.read().split('\n')]
lights = [list(line[0][1:-1]) for line in lines]
lights = [list(map(lambda c: 1 if c == '#' else 0, light)) for light in lights]
button_lists = [[list(map(int, btn[1:-1].split(','))) for btn in line[1:-1]] for line in lines]
# print(lights)
# print(button_lists)
res = 0
for i, light in enumerate(lights):
buttons = button_lists[i]
for cnt in range(1, len(buttons)):
found = False
for combo in itertools.combinations(buttons, cnt):
curr = [0]*len(light)
for btn in combo:
for num in btn:
curr[num] += 1
for i in range(len(curr)):
curr[i] %= 2
if curr == light:
found = True
break
if found:
res += cnt
break
print(res)