Advertisement
Guest User

Untitled

a guest
Dec 18th, 2022
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. # Input: List of lines "<#>,<#>,<#>" (x,y,z coords of unit cubes)
  2. # Output: Number of faces not connected to another cube
  3.  
  4. cubes = []
  5.  
  6. input_data = open(r"c:\users\edward\desktop\personal\aoc2022\18_input.txt")
  7. for input_line in input_data.read().splitlines():
  8.     input_line = input_line.replace("\n", "")
  9.     coordinates = input_line.split(",")
  10.     x, y, z = int(coordinates[0]), int(coordinates[1]), int(coordinates[2])
  11.     cubes.append([x, y, z])
  12.  
  13. offsets = [
  14.     [1, 0, 0],
  15.     [-1, 0, 0],
  16.     [0, 1, 0],
  17.     [0, -1, 0],
  18.     [0, 0, 1],
  19.     [0, 0, -1]
  20. ]
  21.  
  22. number_faces = 0
  23. for cube in cubes:
  24.     for offset in offsets:
  25.         adjacent = False
  26.         for cube2 in cubes:
  27.             if cube2[0] == cube[0] + offset[0] and cube2[1] == cube[1] + offset[1] and cube2[2] == cube[2] + offset[2]:
  28.                 adjacent = True
  29.                 break
  30.         if not adjacent:
  31.             number_faces += 1
  32.  
  33. print (number_faces)
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement