-
Notifications
You must be signed in to change notification settings - Fork 0
/
day12.py
63 lines (52 loc) · 1.52 KB
/
day12.py
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
def main():
with open("input/input12.txt") as f:
lines = [line.rstrip() for line in f]
lines.remove("")
initial = lines[0][15:]
initial = list(initial)
print("".join(initial))
oldState = list(initial)
print(oldState)
for i in range(5):
oldState.insert(0, ".")
oldState.insert(len(oldState), ".")
print(oldState)
newState = ["." for i in range(400)]
notes = lines[1:len(lines)]
print(notes)
noteDic = {}
for note in notes:
noteDic[note[:5]] = note[-1:]
# print(noteDic)
# print(oldState)
history = []
for k in range(194):
if "".join(oldState) in history:
print("".join(oldState))
print(k)
history.append("".join(oldState))
for i in range(2, len(newState)):
lookup = oldState[i-2:i+3]
if len("".join(lookup)) < 5:
break
# print("lookup:", "".join(lookup))
for key, val in noteDic.items():
# print("key:", key)
if "".join(lookup) == key:
# print("ADDED")
# print(newState)
# print("val", val)
newState[i] = val
break
oldState = list(newState)
newState = ["." for i in range(400)]
left = 50000000000 - 194
total = 0
x = -5
for item in oldState:
if item == "#":
total += x + left
x+=1
print(total)
if __name__ == "__main__":
main()