Created
January 30, 2021 08:09
-
-
Save jackdreilly/d301c1ce13ca202d084fdb24edf802a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with open("data/17.txt") as fn: | |
r = fn.read().strip() | |
dim = 5 | |
cubes = { | |
(x, y) + tuple([0] * (dim - 2)) | |
for x, row in enumerate(r.split("\n")) | |
for y, col in enumerate(row) | |
if col == "#" | |
} | |
def perms(i): | |
if not i: | |
yield tuple() | |
return | |
for j in range(-1, 2): | |
for p in perms(i - 1): | |
yield (j, *p) | |
_perms = list(perms(dim)) | |
perms = lambda cube: {tuple(map(sum, zip(cube, perm))) for perm in _perms} | |
for _ in range(6): | |
cubes = { | |
cube | |
for ct, cube in [ | |
(len(perms(cube).intersection(cubes)), cube) | |
for cube in {perm_cube for cube in cubes for perm_cube in perms(cube)} | |
] | |
if (cube in cubes and ct in {3, 4}) or ct == 3 | |
} | |
print(len(cubes)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment