Day18 part1
This commit is contained in:
parent
58f2b05590
commit
dcf50da61c
2025
2022/full/day18.txt
Normal file
2025
2022/full/day18.txt
Normal file
File diff suppressed because it is too large
Load Diff
76
2022/python/day18.py
Normal file
76
2022/python/day18.py
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
import matrix
|
||||||
|
import shared
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from mpl_toolkits.mplot3d import Axes3D
|
||||||
|
import numpy as np
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from typing import Set, Tuple
|
||||||
|
from functools import cached_property
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Cube:
|
||||||
|
x: int
|
||||||
|
y: int
|
||||||
|
z: int
|
||||||
|
neighbors: Set[Tuple[int,int,int]] = None
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def xyz(self):
|
||||||
|
return (self.x,self.y,self.z)
|
||||||
|
|
||||||
|
def set_neighbors(self):
|
||||||
|
# Generate the six neighbors
|
||||||
|
# Look at a die 6 to the left, 2 on top, one on right
|
||||||
|
offsets = (
|
||||||
|
(1,0,0), # 1
|
||||||
|
(0,0,1), # 2
|
||||||
|
(0,-1,0),# 3
|
||||||
|
(0,1,0), # 4
|
||||||
|
(0,0,-1),# 5
|
||||||
|
(-1,0,0) # 6
|
||||||
|
)
|
||||||
|
self.neighbors = set([(self.x+o[0], self.y+o[1], self.z+o[2]) for o in offsets])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# @shared.profile
|
||||||
|
def part1(rows):
|
||||||
|
cubes = []
|
||||||
|
for row in rows:
|
||||||
|
x,y,z = row
|
||||||
|
cube = Cube(x=x,y=y,z=z)
|
||||||
|
cube.set_neighbors()
|
||||||
|
cubes.append(cube)
|
||||||
|
|
||||||
|
potential = len(cubes) * 6
|
||||||
|
for idx in range(len(cubes)):
|
||||||
|
cube = cubes[idx]
|
||||||
|
others = cubes[:idx] + cubes[idx+1:]
|
||||||
|
for other in others:
|
||||||
|
if other.xyz in cube.neighbors:
|
||||||
|
potential -= 1
|
||||||
|
print(potential)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# @shared.profile
|
||||||
|
def part2(coords):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
rows = [map(int,row.split(",")) for row in shared.load_rows(18)]
|
||||||
|
with shared.elapsed_timer() as elapsed:
|
||||||
|
part1(rows)
|
||||||
|
print("🕒", elapsed())
|
||||||
|
with shared.elapsed_timer() as elapsed:
|
||||||
|
part2(rows)
|
||||||
|
print("🕒", elapsed())
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
13
2022/samples/day18.txt
Normal file
13
2022/samples/day18.txt
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
2,2,2
|
||||||
|
1,2,2
|
||||||
|
3,2,2
|
||||||
|
2,1,2
|
||||||
|
2,3,2
|
||||||
|
2,2,1
|
||||||
|
2,2,3
|
||||||
|
2,2,4
|
||||||
|
2,2,6
|
||||||
|
1,2,5
|
||||||
|
3,2,5
|
||||||
|
2,1,5
|
||||||
|
2,3,5
|
Loading…
Reference in New Issue
Block a user