Unable to load image

Day 18 AoC: A nice break :marseybeanrelieved:

This one was very easy compared to the last two days

10
Jump in the discussion.

No email address required.

Today's challenge gave me leeway to be lazy and retarded, so lazy and retarded I shall be.

foo = []
with open('day18_input.txt', 'r') as inp:
    foo = inp.read().split('\n')

cube_grid = [[[False for x in range(21)] for y in range(21)] for z in range(21)]
n = 0
for f in foo:
    f = [int(i) for i in f.split(',')]
    n_delta = 0
    for i in [[f[0]+1,f[1],f[2]],[f[0]-1,f[1],f[2]],[f[0],f[1]+1,f[2]],[f[0],f[1]-1,f[2]],[f[0],f[1],f[2]+1],[f[0],f[1],f[2]-1]]:
        if cube_grid[i[0]][i[1]][i[2]]:
            n_delta -= 1
        else:
            n_delta += 1
    cube_grid[f[0]][f[1]][f[2]] = True
    n += n_delta
print(n)

visited = [[[False for x in range(21)] for y in range(21)] for z in range(21)]
check = [[0,0,0]]
while(len(check) > 0):
    f = check[0]
    check = check[1:]
    for i in [[f[0]+1,f[1],f[2]],[f[0]-1,f[1],f[2]],[f[0],f[1]+1,f[2]],[f[0],f[1]-1,f[2]],[f[0],f[1],f[2]+1],[f[0],f[1],f[2]-1]]:
        if 20 >= i[0] >= 0 and 20 >= i[1] >= 0 and 20 >= i[2] >= 0 and not cube_grid[i[0]][i[1]][i[2]] and not visited[i[0]][i[1]][i[2]]:
            check.append(i)
            visited[i[0]][i[1]][i[2]] = True

for z in range(21):
    for y in range(21):
        for x in range(21):
            if not cube_grid[x][y][z] and not visited[x][y][z]:
                f = [x,y,z]
                for i in [[f[0]+1,f[1],f[2]],[f[0]-1,f[1],f[2]],[f[0],f[1]+1,f[2]],[f[0],f[1]-1,f[2]],[f[0],f[1],f[2]+1],[f[0],f[1],f[2]-1]]:
                    if 20 >= i[0] >= 0 and 20 >= i[1] >= 0 and 20 >= i[2] >= 0 and cube_grid[i[0]][i[1]][i[2]]:
                        n -= 1
print(n)
Jump in the discussion.

No email address required.

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.