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.
27 lines
867 B
27 lines
867 B
2 years ago
|
#reading input
|
||
|
with open('input18.txt','r') as f:
|
||
|
inp = f.read().splitlines(keepends=False)
|
||
|
|
||
|
cubes = []
|
||
|
sides = {}
|
||
|
surface = 0
|
||
|
|
||
|
for line in inp:
|
||
|
x, y, z = line.split(',')
|
||
|
cubes.append((int(x), int(y), int(z)))
|
||
|
|
||
|
#main function
|
||
|
for cube in cubes:
|
||
|
x, y, z = cube
|
||
|
sides[((x - 1, x),(y, y),(z, z))] = sides.get(((x - 1, x),(y, y),(z, z)), 0) + 1
|
||
|
sides[((x, x + 1),(y, y),(z, z))] = sides.get(((x, x + 1),(y, y),(z, z)), 0) + 1
|
||
|
sides[((x, x),(y - 1, y),(z, z))] = sides.get(((x, x),(y - 1, y),(z, z)), 0) + 1
|
||
|
sides[((x, x),(y, y + 1),(z, z))] = sides.get(((x, x),(y, y + 1),(z, z)), 0) + 1
|
||
|
sides[((x, x),(y, y),(z - 1, z))] = sides.get(((x, x),(y, y),(z - 1, z)), 0) + 1
|
||
|
sides[((x, x),(y, y),(z, z + 1))] = sides.get(((x, x),(y, y),(z, z + 1)), 0) + 1
|
||
|
|
||
|
for side in sides:
|
||
|
if sides[side] == 1:
|
||
|
surface += 1
|
||
|
|
||
|
print(surface)
|