Solve day 18.

This commit is contained in:
2023-12-30 12:10:52 -05:00
parent 482d5e4aa7
commit 2d9b37be55
2 changed files with 85 additions and 7 deletions

View File

@@ -1,19 +1,26 @@
# Times # Times
- Day 1: 7:52 ... so slow brah :/ top 100 required 2:05... - Day 1: 7:52 ... so slow brah :/ top 100 required 2:05...
- Day 2: 22:30 ... I mistyped the first and second was just bad top 100 would have been 6:16 (doable?) - Day 2: 22:30 ... I mistyped the first and second was just bad top 100 would
have been 6:16 (doable?)
- Day 3: 13:08 actually decent but top 100 required 5:24 - Day 3: 13:08 actually decent but top 100 required 5:24
- Day 4: 7:08 but top 100 required 3:33 still okay - Day 4: 7:08 but top 100 required 3:33 still okay
- Day 5: 11:56 but 7:58 for top 100... getting better? - Day 5: 11:56 but 7:58 for top 100... getting better?
- Day 6: 3:50 but 2:25 for leaderboard :D - Day 6: 3:50 but 2:25 for leaderboard :D
- Day 7: 27:55 and 14:47 for leaderboard; okay, I would say - Day 7: 27:55 and 14:47 for leaderboard; okay, I would say
- Day 8: 61:00 and 10:00 for leaderboard; I need template code for searching coordinate systems - Day 8: 61:00 and 10:00 for leaderboard; I need template code for searching
coordinate systems
- Day 9: 58:00 and 7:32 for leaderboard; I need code for 2D stuff - Day 9: 58:00 and 7:32 for leaderboard; I need code for 2D stuff
- Day 10: 25:20 and 12:17 for leaderboard; okay, okay - Day 10: 25:20 and 12:17 for leaderboard; okay, okay
- Day 11: 45:00 and 18:00 for leaderboard; arg, it was doable man - Day 11: 45:00 and 18:00 for leaderboard; arg, it was doable man
- Day 12: 39:45 and 9:46 for leaderboard; the people are ready for their searches :D - Day 12: 39:45 and 9:46 for leaderboard; the people are ready for their
- Day 13: 44:00 and 12:56 for leaderboard; these people are just good, seriously searches :D
- Day 13: 44:00 and 12:56 for leaderboard; these people are just good,
seriously
- Day 14: 35:00 and 14:54; I just have to get that much quicker... 2D code! - Day 14: 35:00 and 14:54; I just have to get that much quicker... 2D code!
- Day 15: 150:00 and 27:00; I didn't use Manhatten dist initially, lot's of debugging - Day 15: 150:00 and 27:00; I didn't use Manhattan dist initially, lot's of
- Day 16: 52:00 and 64:00; ARE YOU SAYING I WOULD HAVE MADE THE LEADERBOARD?!?!?!?!?!?!?! debugging
- Day 17: - Day 16: 52:00 and 64:00; ARE YOU SAYING I WOULD HAVE MADE THE
LEADERBOARD?!?!?!?!?!?!?!
- Day 17: Second one was fun with having to detect the repetition.
- Day 18: 12:00 and 32:00; really straightforward and of course way too slow.

71
d18.py Normal file
View File

@@ -0,0 +1,71 @@
from lib import *
EXAMPLE = """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
"""
def solve(input: Input, second=False):
cubes = set([tuple(map(int, l.split(",")))for l in input.text.splitlines()])
res = len(cubes) * 6
if second:
min_x = min([c[0] for c in cubes]) - 1
max_x = max([c[0] for c in cubes]) + 1
min_y = min([c[1] for c in cubes]) - 1
max_y = max([c[1] for c in cubes]) + 1
min_z = min([c[2] for c in cubes]) - 1
max_z = max([c[2] for c in cubes]) + 1
surrounded = set([(x, y, z)
for x in range(min_x, max_x + 1)
for y in range(min_y, max_y + 1)
for z in range(min_z, max_z + 1)])
surrounded -= cubes
vs = [(min_x, min_y, min_z)]
while vs:
(x, y, z) = vs.pop()
for dx, dy, dz in [(1, 0, 0), (-1, 0, 0), (0, 1, 0), (0, -1, 0), (0, 0, 1), (0, 0, -1)]:
t = x + dx, y + dy, z + dz
if t in surrounded:
surrounded.remove(t)
vs.append(t)
for x, y, z in list(surrounded):
for dx, dy, dz in [(1, 0, 0), (-1, 0, 0), (0, 1, 0), (0, -1, 0), (0, 0, 1), (0, 0, -1)]:
nc = x + dx, y + dy, z + dz
if nc in cubes:
res -= 1
for x, y, z in list(cubes):
for dx, dy, dz in [(1, 0, 0), (-1, 0, 0), (0, 1, 0), (0, -1, 0), (0, 0, 1), (0, 0, -1)]:
nc = x + dx, y + dy, z + dz
if nc in cubes:
res -= 1
return res
def main():
DAY_INPUT = "i18.txt"
print("Example 1:", solve(Input(EXAMPLE)))
print("Solution 1:", solve(Input(DAY_INPUT)))
# 10:30........
print("Example 2:", solve(Input(EXAMPLE), True))
print("Solution 2:", solve(Input(DAY_INPUT), True))
assert solve(Input(DAY_INPUT), True) == 2064
# 30:00
return
if __name__ == "__main__":
main()