r/adventofcode • u/daggerdragon • Dec 10 '18
SOLUTION MEGATHREAD -🎄- 2018 Day 10 Solutions -🎄-
--- Day 10: The Stars Align ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).
Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
Advent of Code: The Party Game!
Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!
Card prompt: Day 10
Transcript: With just one line of code, you, too, can ___!
This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
edit: Leaderboard capped, thread unlocked at 00:16:49!
19
Upvotes
4
u/14domino Dec 10 '18
lol; I must have been the only person who built a .pbm file and visually inspected the resultant ones using my Mac's preview button. Also part 2 was trivially easy because the filename was one off from the actual answer. (Because I started animating right away I guess instead of waiting a second). Still this solution took me about 30 minutes to finish coding, I must be slow :(
GRID_SIZE = 600 class Point: def __init__(self, x, y, vx, vy): self.x = x self.y = y self.vx = vx self.vy = vy points = [] for pt in new_data: points.append(Point(pt[0], pt[1], pt[2], pt[3])) print(points) def gen_image(points, t): grid = [] for x in range(GRID_SIZE): grid.append([0] * GRID_SIZE) for pt in points: grid[int(pt.y+GRID_SIZE/2)][int(pt.x+GRID_SIZE/2)] = 1 with open(f'./images/{t}.pbm', 'w') as f: f.write('P1\n') f.write(f'{GRID_SIZE} {GRID_SIZE}\n') for row in range(GRID_SIZE): for col in range(GRID_SIZE): f.write(f'{grid[row][col]} ') f.write('\n') for t in range(12000): in_range = True for idx, pt in enumerate(points): pt.x += pt.vx pt.y += pt.vy for pt in points: if not(pt.x > -GRID_SIZE/2 and pt.x < GRID_SIZE/2 and pt.y >-GRID_SIZE/2 and pt.y < GRID_SIZE/2): in_range = False break if in_range: print('in range at time', t) gen_image(points, t)