Solve 2020/11
parent
faff40a314
commit
a8c18e6c8a
@ -0,0 +1,10 @@
|
||||
L.LL.LL.LL
|
||||
LLLLLLL.LL
|
||||
L.L.L..L..
|
||||
LLLL.LL.LL
|
||||
L.LL.LL.LL
|
||||
L.LLLLL.LL
|
||||
..L.L.....
|
||||
LLLLLLLLLL
|
||||
L.LLLLLL.L
|
||||
L.LLLLL.LL
|
@ -0,0 +1,93 @@
|
||||
LLLL.LLLLL.LLLLLLLLLLLLLLLL.L.LLLLLL.LLLL..L.LLLLLLLL.LLLLLL.LLLL..LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLLLLLLLLLLLLLLLLLLL.LLL.LLLLLLLLL.L..LLLLLLLL.LLLLLL.LLLLLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLL
|
||||
LLLLLLLLLL.LLLLLLLLLLL.LLLL.LLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLL.LLLLL.LL.LLLL.LL.LLLLLLLLLLLLLLLLLLLL
|
||||
LLL.LLLLLLLLLLL.LLLL.LLLLLLLLLL.LL.L.LLLLLLL.LLLLLLLL.LLLLLL.LLLLL.LLLLLLL.LLLLLLLL.LLLLL.LLLLLLLL
|
||||
LLLLLLLLLL.LLLLLLLLLLLLLLLL.LLLL.LLL.LLLL.LLLLLLLLLLL.LLLLLLLLLLLL.LLLLLLL.LLLLLLLL.LLLLLLLLLLLLLL
|
||||
LLLLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLLLLLL.LLLLLLLLLLLLLL
|
||||
...L..LL.LL.LLL....L......L..L.....L.....L....L.LL.....LL..L.L...LL.L...LL..L.L...L.LL...L..LL..L.
|
||||
LLLLLLLLLLLLLLLLLL.L.LLLLLL.LLLLLLLL.LLLLL.L.LLLLLLLLLLLLLLL.LLLLL.LLLLLLLLLL.LLLLL.LLLLLLLL.LLLLL
|
||||
LLLLLLLLL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LLL.LLLLLLLLLLLLLL
|
||||
..L...LLL........LL....L.....L.....L..L..L.....L.L.LL...L......LLLLL.L.L...........L.LL.....LL...L
|
||||
LLLLLLLLLLLLLLLLLLLL.LLLLLL.LLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLLLLL.LLLLLLL.LLLLLLLL.LLLLLLLLLLLLLL
|
||||
LLLLLLLLLL.L.LLL.LLL.LLLLLL.LLLLLLLL.LLLLL.LLLLLLLLLL.LLLLLLLLLLLL.LLLLLLLLLLLLLLLL.LLLLLLL.LLLLLL
|
||||
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLL.LLLLLLLL.LLLLLL.LLLLL.LLLLLLL.LLLLLLLL.LLLLLLLLLL.LLL
|
||||
LLLLLLLLLLLLLLLL.LLLLLLLLLL.LLLLLLLLLLLLL.LL.LL.LLLLLLLLLLLL.LLLLL.LLLLLLLLLLLL.LL.LLL.LLLLLLLLLLL
|
||||
LLLLLLLLLL.LLLLLLLLLLLLLLLL.LLLLLLL...LLLLLLLLLLLLLLL.LLLLLL.LLLLL.LLLLLLL.LLLLLLLL.LLLLLLLLLLL.LL
|
||||
LLLLLLL.LL.LLLLLLLLL.LLLLLLLLLLLLLLL.LLLLLLL..LLLLLLL.LLLLLL.LLLLL.LLLLLLL.LLLLLLLL.LLLLLLLLLLLLLL
|
||||
....L..L.L.LL..LLL..L....LL...L.L..LL.L......L...LLL.L.L.L.....L.......L......LL.....L..L.L..LL...
|
||||
LLLLLLLLLL.LLLLLLLLL.LLLLLL.LLLLLLLL.LLLLLL.LLLLLLLLLLLLLLLLLLLLLL.LLLLLLL.LLLLLLL.LLLLLLLLLLLLL.L
|
||||
LLLLLLLLLL.LLLLLLLLL.LLLL.L.LLL.LLLL.LLLLLLL.LLLLLLLLLLLLLLL.LLLLL.LLLLLLLLLLLLLLLL.LLLLLLLLLLLLLL
|
||||
LLLLLLLLLLLLL.LLLLLL.LLLLLLLLLLLLLL...LLLLLL.LLLLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLL.LLLLLLLLLLLLLL
|
||||
LLLLLLLLLL.LLLLLLLLLLLL.LLLLLLLLL..LLLLLLLLLLLLLLLLLL.LLLLLLL.LLLL.LLLLLLL.LLLLLLLL.LLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.L.LLLLLLL.LLLLLLLLLLLLLLLLLLLLLLL.LLLL.LLL.LLLLLL.LLLLLLLLLLLLLLLLLLLLLL.LLL.LLLLLLLLLL
|
||||
LL.LLLLLLL.LLLLLLLLL.LLLLLL.LLLLLLLL.LLLLLLLL.LLLLLLL.LLL.LL.LLLLL.LLLLLLL.LLLLLLLL.LLLLLLLLLLLLLL
|
||||
..LL.LLL...LLL.....L.L.L......L......L........L.LL......LLL..LL..L..L.LLL..LL..LL.L.....L.LL....L.
|
||||
LLLLLLLLLL.LL.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLLL.LLLLLLLL..LLLL.LLLLLLLL
|
||||
LLLLLLLLLL.LLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLL.LL.LLLLLL.L.LLLLLLLLL.L.LLLLL.LL.L.LLLLLLLLLLLL
|
||||
LLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLL.LLLLLLLLLLLLLLLL.LLLLLL.LLLLL.LLLLLLL.LLLLLLLL.LLLLLLLLLLLLLL
|
||||
LLLLLLLLL.LLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLL.LLLLLLLLLLLLL.LLLLLLL.LLLLLLL.LL.LLLLL.LLLLLLLLLLL.LL
|
||||
LLLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLLLLLLLL.LLLLLLLLLL.LLLLL.LLL.LLL.LLLLL.LL.LLLLLLLLLLLLLL
|
||||
L..L..LL..LLL...L......L.....L...LL..L..L.....L.L...LL......L.L.LLL.L..L....L....L...L.L........LL
|
||||
LLLLLLLLLL.LL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LLLLLLLLLLLLLL
|
||||
LLLLLLLLLLLLLLLLLLLL..LLLLL.LLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLL.LLLLL.LLLLLL..LLLLLLLL.LLLLLLLLLLLLLL
|
||||
........LLLLLL.LL.L..L...L...LLL....L.......LLLL..L.LL.L..L.L.LLL...L...L.......L..L.....L.L.L..LL
|
||||
LLLLLLLLLL.LLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLL.LL.LLL..LLLL.LLLLLLL.LLLLLLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLL.LLLLLLLLL.LLLLLL.LLLLLLLLLLLLLLL..LLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLL.LLLLLLLLLL
|
||||
L.LLLLL.LLLLLLLLLLLL.LLLLLL.LLLLLLLLLLL.LLLL.LLL.LLLLLLLLLLL.LLLLLLLLLLLLL.LLLLLLLL.LLLLL.LLLLLLLL
|
||||
LLLLLL.LLL.LLLLLLLLLLLLL.LLLLLLLLLLL.LLLLLLL.LLLLLLLL.LLLLLLLLLLLL.LLL.L.L.LLLLLLLL.LLLLLLLLLLLLLL
|
||||
LLL.LLLLLL.LLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLLLLLLLLLLLLL.LLLLL.LLLLLLL.LLLLL.LL.LLLLLLLLLLLLLLLLLLLLL.LLLLLLL..LLLLLLL.LLLLLLLLLLLLLL
|
||||
..LL..L....L.......L....L....LL...L.L..L.........LL..L..LL.L....LLL.L.LLL...L.....LL.....LL.LL....
|
||||
LLLLLLLLLL.LLLLLL.LL.LLLLLLLL..LLLLL.LLLLLLLLLLLLLLLL.LLLLLL.L.LLLLLLLLLLL.LLLLLLLL.LLLLLLLLLL.LLL
|
||||
L.LLLLLLLLLLLL.LLLLLLLLLLLL.LLLLLLLLLLLLLLLL.LLL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LL.LLLLL.LLLLLLLL
|
||||
LLLLL.LLLLLLLLLLLLLL.LLLLLL.LLLLLLLL.LLLLLLLLLLLLLL.L.LLLLLL.LLLLL.LLLLLLL.LLLLLLLL.L.LLLLLLLLLLLL
|
@ -0,0 +1,49 @@
|
||||
data = open('input', 'r').readlines()
|
||||
data = [list(x.strip()) for x in data]
|
||||
|
||||
|
||||
def neighbors(mat, x, y):
|
||||
height = len(mat)
|
||||
width = len(mat[0])
|
||||
for i in range(3):
|
||||
for j in range(3):
|
||||
dx = i - 1
|
||||
dy = j - 1
|
||||
if dx == 0 and dy == 0:
|
||||
continue
|
||||
if x + dx < 0 or y + dy < 0:
|
||||
continue
|
||||
if x + dx >= height or y + dy >= width:
|
||||
continue
|
||||
yield data[x + dx][y+dy]
|
||||
|
||||
|
||||
def serialize(mat):
|
||||
return '\n'.join([''.join(line) for line in mat])
|
||||
|
||||
|
||||
def apply(mat):
|
||||
newData = []
|
||||
for x, _ in enumerate(mat):
|
||||
line = []
|
||||
for y, _ in enumerate(mat[x]):
|
||||
neigh = list(neighbors(mat, x, y))
|
||||
if mat[x][y] == 'L' and '#' not in neigh:
|
||||
line.append('#')
|
||||
elif mat[x][y] == '#' and neigh.count('#') >= 4:
|
||||
line.append('L')
|
||||
else:
|
||||
line.append(mat[x][y])
|
||||
newData.append(line)
|
||||
return newData
|
||||
|
||||
|
||||
prev = ''
|
||||
|
||||
while serialize(data) != prev:
|
||||
prev = serialize(data)
|
||||
data = apply(data)
|
||||
|
||||
|
||||
# print(serialize(data))
|
||||
print(prev.count('#'))
|
@ -0,0 +1,67 @@
|
||||
import math
|
||||
|
||||
data = open('input', 'r').readlines()
|
||||
data = [list(x.strip()) for x in data]
|
||||
|
||||
|
||||
def polarToXY(direction, distance):
|
||||
if direction % 2 == 1:
|
||||
distance *= math.sqrt(2)
|
||||
x = distance * math.cos(direction * math.pi / 4)
|
||||
y = distance * math.sin(direction * math.pi / 4)
|
||||
return [round(x), round(y)]
|
||||
|
||||
|
||||
def getTile(mat, x, y):
|
||||
if x < 0 or x >= len(mat):
|
||||
raise Exception('oob: x')
|
||||
if y < 0 or y >= len(mat[x]):
|
||||
raise Exception('oob: y')
|
||||
return mat[x][y]
|
||||
|
||||
|
||||
def neighbors(mat, x, y):
|
||||
neighbor_list = []
|
||||
for direction in range(8):
|
||||
try:
|
||||
distance = 1
|
||||
i, j = polarToXY(direction, distance)
|
||||
neighbor = getTile(mat, x + i, y + j)
|
||||
while neighbor == '.':
|
||||
distance += 1
|
||||
i, j = polarToXY(direction, distance)
|
||||
neighbor = getTile(mat, x + i, y + j)
|
||||
neighbor_list.append(neighbor)
|
||||
except:
|
||||
pass
|
||||
|
||||
return neighbor_list
|
||||
|
||||
|
||||
def serialize(mat):
|
||||
return '\n'.join([''.join(line) for line in mat])
|
||||
|
||||
|
||||
def apply(mat):
|
||||
newData = []
|
||||
for x, _ in enumerate(mat):
|
||||
line = []
|
||||
for y, _ in enumerate(mat[x]):
|
||||
neigh = list(neighbors(mat, x, y))
|
||||
if mat[x][y] == 'L' and '#' not in neigh:
|
||||
line.append('#')
|
||||
elif mat[x][y] == '#' and neigh.count('#') >= 5:
|
||||
line.append('L')
|
||||
else:
|
||||
line.append(mat[x][y])
|
||||
newData.append(line)
|
||||
return newData
|
||||
|
||||
|
||||
prev = ''
|
||||
|
||||
while serialize(data) != prev:
|
||||
prev = serialize(data)
|
||||
data = apply(data)
|
||||
|
||||
print(prev.count('#'))
|
Loading…
Reference in New Issue