You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

53 lines
1.6 KiB

#!/usr/bin/env python3
import sys
from copy import deepcopy
def imagine(im):
for y in im:
l = ''
for x in y: l += x
print(l)
def n(im,x,y,o):
index = ''
h = [(-1,-1), (-1,0), (-1,1), (0,-1), (0,0), (0,1), (1,-1), (1,0), (1,1)]
for j,i in h:
if (0 <= x+i < len(im[0]) and 0 <= y+j < len(im)): index += '0' if im[y+j][x+i] == '.' else '1'
else: index += '0' if o == '.' else '1'
return algo[int(index,2)]
def enhance(im, o):
nex = deepcopy(im)
for y in range(len(im)):
for x in range(len(im[0])):
nex[y][x] = n(im,x,y,o)
return nex, '.' if o == '#' or mode == 'k' else '#'
if __name__ == '__main__':
algo, im = open(sys.argv[1]).read().split('\n\n')
algo = list(algo.strip('\n'))
im = [list(i) for i in im.split('\n') if i != '']
print('------------------ start -------------------')
bim = [[im[i-50][j-50] if (49 < i <= len(im)+49 and 49 < j <= len(im[0])+49) else '.' for j in range(len(im[0]) + 100)] for i in range(len(im) + 100)]
imagine(bim)
mode = 's' if algo[0] == '#' else 'k'
nim, o = bim, '.'
for i in range(50):
print('-------------------- ' + str(i) + ' ---------------------')
nim, o = enhance(nim,o)
imagine(nim)
if i == 1: c1 = nim
# challenge 1
res1 = str(sum(sum(1 if i == '#' else 0 for i in j) for j in c1))
print("challenge 1:" + "\n" + res1 + "\n")
# challenge 2
res2 = str(sum(sum(1 if i == '#' else 0 for i in j) for j in nim))
print("challenge 2:" + "\n" + res2 + "\n")