update day 11 soln to remove unneded crud

This commit is contained in:
Peter 2020-12-12 22:42:24 +08:00
parent 3d128f86ec
commit ac6bfd9c71
2 changed files with 9 additions and 137 deletions

115
11/a.py
View File

@ -15,13 +15,9 @@ def simulate(mat): # Part A.
for j in jdom: for j in jdom:
adjrows.pop(0) adjrows.pop(0)
adjrows.append(mat[j+1]+['.']) if j+1 in jdom else adjrows.append([ '.' for x in idom ]+['.']) adjrows.append(mat[j+1]+['.']) if j+1 in jdom else adjrows.append([ '.' for x in idom ]+['.'])
# print(adjrows)
for i in idom: for i in idom:
cell = mat[j][i] cell = mat[j][i]
# print(i,j, cell)
if cell == "#": if cell == "#":
# print(adj(adjrows))
# print( [[ x[i] for i in range(i-1,i+2) ] for x in adjrows ] )
adjm = adj(adjrows, i).count('#')-1 adjm = adj(adjrows, i).count('#')-1
if adjm > 3: if adjm > 3:
mat_[j][i] = 'L' mat_[j][i] = 'L'
@ -31,120 +27,15 @@ def simulate(mat): # Part A.
if adjm == 0: if adjm == 0:
mat_[j][i] = '#' mat_[j][i] = '#'
d += 1 d += 1
# [ print(x) for x in mat_ ]
if d > 0: if d > 0:
mat = simulate(mat_) mat = simulate(mat_)
return mat return mat
return mat return mat
def a(mat): #Holy [] this is slow! #Holy [] this is slow!
# [ print(''.join(x)) for x in simulate(mat) ] [ print(''.join(x)) for x in simulate(mat) ]
count = [] count = []
[ count.append(x.count('#')) for x in simulate(mat) ] [ count.append(x.count('#')) for x in simulate(mat) ]
return sum(count) print(sum(count))
# SEE b.py FOR PART 2 ANSWER # SEE b.py FOR PART 2 ANSWER
# SEE b.py FOR PART 2 ANSWER
# SEE b.py FOR PART 2 ANSWER
# NOT USING THIS AS MY ANSWER.
# # print(a(mat))
# def diagrtx(mat, r, nc, pc, jdom):
# [c, pb, nb] = [0, False, False]
# for x in r:
# y = -x + nc
# if nb == False and -y in jdom:
# cell = mat[-y][x]
# if cell == '#':
# c += 1
# nb = True
# elif cell == "L":
# nb = True
# y = x + pc
# if pb == False and -y in jdom:
# cell = mat[-y][x]
# if cell == '#':
# c += 1
# pb = True
# elif cell == "L":
# pb = True
# return c
# def hrtx(mat, r, j, idom):
# for x in r:
# if x in idom:
# cell = mat[j][x]
# if cell == "#":
# return 1
# break
# elif cell == "L":
# break
# return 0
# def vrtx(mat, r, i, jdom):
# for y in r:
# if -y in jdom:
# cell = mat[-y][i]
# if cell == "#":
# return 1
# break
# elif cell == "L":
# break
# return 0
# def RTX(mat, idom, jdom, i, j): #generate diagonals - this is quality '3am' code right here
# nc = i + j
# pc = j - i
# # print(nc, pc)
# # print(list(range(i,len(mat[0]))))
# # [ print(x) for x in mat ]
# rl = range(i-1, -1, -1)
# lr = range(i+1, len(mat[0]))
# u = range(j+1, 1)
# d = range(j-1, -len(mat), -1)
# return (
# diagrtx(mat, rl, nc, pc, jdom) + hrtx(mat, rl, -j, idom)
# + diagrtx(mat, lr, nc, pc, jdom) + hrtx(mat, lr, -j, idom)
# + vrtx(mat, u, i, idom) + vrtx(mat, d, i, idom)
# )
# #wtf part over.
# def simulate2(mat):
# idom = range(len(mat[0]))
# jdom = range(len(mat))
# mat_ = deepcopy(mat)
# d = 0
# for j in jdom:
# for i in idom:
# c = RTX(mat, idom, jdom, i, j)
# cell = mat[j][i]
# # print(i,j, c, cell)
# if cell == "#":
# if c > 4:
# mat_[j][i] = 'L'
# d += 1
# elif cell == "L":
# if c == 0:
# mat_[j][i] = '#'
# d += 1
# [ print(''.join(x)) for x in mat_ ]
# print('')
# if d > 0:
# mat = simulate2(mat_)
# return mat
# return mat
# #increment x
# # print([-x + nc if -(-x + nc) in jdom else None, x + pc if -(x + pc) in jdom else None])
# # print({x:[-x + nc if -(-x + nc) in jdom else None, x + pc if -(x + pc) in jdom else None] for x in idom})
# def b(mat): #Holy shit this is even slower!
# count = []
# [ count.append(x.count('#')) for x in simulate2(mat) ]
# return sum(count)
# print(b(mat))
# # def rtx(mat, i, j): #raytracer

27
11/b.py
View File

@ -3,7 +3,7 @@ from copy import deepcopy
mat = [ ['.']+list(x)+['.'] for x in open('input').read().replace('L','#').splitlines() ] # mat = [ ['.']+list(x)+['.'] for x in open('input').read().replace('L','#').splitlines() ] #
null = [ '.' for x in range(len(mat[0])) ] null = [ '.' for x in range(len(mat[0])) ]
# cmat = [null] + [ ['.']+[ '0' for y in range(len(mat[0])-2) ]+['.'] for x in mat ] + [null] # cmat = [null] + [ ['.']+[ '0' for y in range(len(mat[0])-2) ]+['.'] for x in mat ] + [null] #cmat is the number of # according to the rule, in matrix form.
mat = [null] + mat + [null] mat = [null] + mat + [null]
def RTX_side(r, d, y, mat): # Yes i know this isn't proper raytracing but haha tech tip nvidia rtx 6900ti funny moment. def RTX_side(r, d, y, mat): # Yes i know this isn't proper raytracing but haha tech tip nvidia rtx 6900ti funny moment.
@ -20,7 +20,6 @@ def RTX_side(r, d, y, mat): # Yes i know this isn't proper raytracing but haha t
elif cell == '#': elif cell == '#':
top = False top = False
c += 1 c += 1
# mat[y+j_d][i] = "Y"
if y-j_d in d and bottom: if y-j_d in d and bottom:
cell = mat[y-j_d][i] cell = mat[y-j_d][i]
if cell == 'L': if cell == 'L':
@ -28,14 +27,12 @@ def RTX_side(r, d, y, mat): # Yes i know this isn't proper raytracing but haha t
elif cell == '#': elif cell == '#':
bottom = False bottom = False
c += 1 c += 1
# mat[y-j_d][i] = "Y"
if side: if side:
if mat[y][i] == "L": if mat[y][i] == "L":
side = False side = False
if mat[y][i] == "#": if mat[y][i] == "#":
side = False side = False
c += 1 c += 1
# mat[y][i] = 'Y'
if c == 3: break if c == 3: break
j_d += 1 j_d += 1
return c return c
@ -46,35 +43,25 @@ def RTX_top(r, i, mat):
return 0 return 0
elif mat[j][i] == '#': elif mat[j][i] == '#':
return 1 return 1
# mat[j][i] = "Y"
return 0 return 0
# mat_ = list(map(list, zip(*mat)))
dim_j = len(mat)-1 dim_j = len(mat)-1
# dim_j = len(mat_)-2
dim_i = len(mat[0])-1 dim_i = len(mat[0])-1
domVERT = range(1,dim_j+1) #Domain for vertical / j values domVERT = range(1,dim_j+1) #Domain for vertical / j values
# [ print(x) for x in mat ]
def RTX_ON(mat): def RTX_ON(mat):
mat_ = deepcopy(mat) mat_ = deepcopy(mat)
d = False d = False
for x in range(1, dim_i): for x in range(1, dim_i):
for y in range(1, dim_j): for y in range(1, dim_j):
# [ print(x) for x in mat ]
# mat[y][x] = 'X'
rN = range(y-1,0,-1) rN = range(y-1,0,-1)
rS = range(y+1,dim_j+1) rS = range(y+1,dim_j+1)
rE = range(x+1, dim_i+1) rE = range(x+1, dim_i+1)
rW = range(x-1, 0, -1) rW = range(x-1, 0, -1)
# print(list(rN), list(rS))
# print(list(rE), list(rW))
c = (RTX_side(rE, domVERT, y, mat) + RTX_side(rW, domVERT, y, mat) + RTX_top(rN, x, mat) + RTX_top(rS, x, mat)) c = (RTX_side(rE, domVERT, y, mat) + RTX_side(rW, domVERT, y, mat) + RTX_top(rN, x, mat) + RTX_top(rS, x, mat))
# cmat[y][x] = (str)(c) # cmat[y][x] = (str)(c) #cmat is the number of # according to the rule, in matrix form.
if mat[y][x] == '#' and c > 4: if mat[y][x] == '#' and c > 4:
mat_[y][x] = 'L' mat_[y][x] = 'L'
d = True d = True
@ -82,13 +69,7 @@ def RTX_ON(mat):
mat_[y][x] = '#' mat_[y][x] = '#'
d = True d = True
if d == True: if d == True:
# print("") #print(""); [ print(x) for x in mat ]; print(""); [ print(x) for x in cmat ]; print(""); [ print(x) for x in mat_ ]; print("") #good ol' print debugging
# print("")
# [ print(x) for x in mat ]
# [ print(x) for x in cmat ]
# print("")
# [ print(x) for x in mat_ ]
# print("")
mat = RTX_ON(mat_) mat = RTX_ON(mat_)
return mat return mat
return mat return mat
@ -96,5 +77,5 @@ def RTX_ON(mat):
simulated = RTX_ON(mat) #This is slow AF simulated = RTX_ON(mat) #This is slow AF
[ print(''.join(x)) for x in simulated ] #output ascii [ print(''.join(x)) for x in simulated ] #output ascii, why not?
print(sum([ x.count('#') for x in simulated ])) print(sum([ x.count('#') for x in simulated ]))