Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cubes = process_input('test2.txt')
- X, Y, Z = [], [], []
- for cube in cubes:
- x0, x1, y0, y1, z0, z1 = cube.coords
- X.append(x0)
- X.append(x1 + 1)
- Y.append(y0)
- Y.append(y1 + 1)
- Z.append(z0)
- Z.append(z1 + 1)
- X = list(set(X))
- Y = list(set(Y))
- Z = list(set(Z))
- X.sort()
- Y.sort()
- Z.sort()
- N = len(X)
- grid = defaultdict(lambda: 0)
- for cube in cubes:
- x0 = X.index(cube.x0)
- x1 = X.index(cube.x1 + 1)
- y0 = Y.index(cube.y0)
- y1 = Y.index(cube.y1 + 1)
- z0 = Z.index(cube.z0)
- z1 = Z.index(cube.z1 + 1)
- value = int(cube.state == 'on')
- for x in range(x0, x1):
- for y in range(y0, y1):
- for z in range(z0, z1):
- grid[(x, y, z)] = value
- total = 0
- for x in range(N-1):
- for y in range(N-1):
- for z in range(N-1):
- total += grid[(x, y, z)] * (X[x+1] - X[x]) * (Y[y+1] - Y[y]) * (Z[z+1] - Z[z])
- print(total)
Advertisement
Add Comment
Please, Sign In to add comment