Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Input: List of lines "<#>,<#>,<#>" (x,y,z coords of unit cubes)
- # Output: Number of faces not connected to another cube
- cubes = []
- input_data = open(r"c:\users\edward\desktop\personal\aoc2022\18_input.txt")
- for input_line in input_data.read().splitlines():
- input_line = input_line.replace("\n", "")
- coordinates = input_line.split(",")
- x, y, z = int(coordinates[0]), int(coordinates[1]), int(coordinates[2])
- cubes.append([x, y, z])
- offsets = [
- [1, 0, 0],
- [-1, 0, 0],
- [0, 1, 0],
- [0, -1, 0],
- [0, 0, 1],
- [0, 0, -1]
- ]
- number_faces = 0
- for cube in cubes:
- for offset in offsets:
- adjacent = False
- for cube2 in cubes:
- if cube2[0] == cube[0] + offset[0] and cube2[1] == cube[1] + offset[1] and cube2[2] == cube[2] + offset[2]:
- adjacent = True
- break
- if not adjacent:
- number_faces += 1
- print (number_faces)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement