-
Notifications
You must be signed in to change notification settings - Fork 0
/
12a.py
66 lines (49 loc) · 1.14 KB
/
12a.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
64
65
66
file_name = "12a.txt"
#file_name = "12ex.txt"
import numpy as np
import re
start = '#..####.##..#.##.#..#.....##..#.###.#..###....##.##.#.#....#.##.####.#..##.###.#.......#............'
#start = '#..#.#..##......###...###'
def preprocess(x):
records = []
for r in x:
row = r.replace('\n','').split('=>')
records.append([row[0].strip(),row[1].strip()])
return records
def xor(s,rec):
for r in rec:
if all([ s[i] == r[0][i] for i in range(5) ]):
print( 'xor ', s, r[1] )
return r[1]
else:
print( 'xor ', s, '.' )
return '.'
def iter(s, r):
print(len(s))
s = '..........' + s + '..............................'
print(s)
sl = [i for i in s]
slx = sl.copy()
cycle = 0
while cycle < 20:
sl = [slx[i] for i in range(len(sl))]
for i in range(0,len(sl)-5):
sli = sl[i:i+5]
res = xor(sli,r)
slx[i+2] = res
cycle += 1
print( ''.join(slx) )
total = 0
for i in range(0,len(slx)):
if slx[i] == '#':
total += (i-10)
print('t->', total)
return
def main():
with open(file_name, 'r') as f:
x = f.readlines()
print(len(x))
records = preprocess(x)
iter(start,records )
#print(x)
main()