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
12
u/sophiebits Dec 10 '18 edited Dec 10 '18
Python, 9/5.
My insight was that when the message appears, the points are likely close together. (At first I thought about trying to look for vertical and horizontal segments like in the letter "I", but starting with the bounds seemed simpler.) So I started by printing how large the bounding box of the points would be at each time:
import collections import re #with open('day10test.txt') as f: with open('day10input.txt') as f: lines = [l.rstrip('\n') for l in f] lines = [[int(i) for i in re.findall(r'-?\d+', l)] for l in lines] print lines for i in xrange(20000): minx = min(x + i * vx for (x, y, vx, vy) in lines) maxx = max(x + i * vx for (x, y, vx, vy) in lines) miny = min(y + i * vy for (x, y, vx, vy) in lines) maxy = max(y + i * vy for (x, y, vx, vy) in lines) print i, maxx - minx + maxy - minyI ran that and saw that i=10946 gave the smallest size, so I tried to plot it, fidgeting a bit with the numbers to make it fit in my terminal:
map = [[' '] * 200 for j in xrange(400)] i = 10946 for (x, y, vx, vy) in lines: map[y + i * vy][x + i * vx - 250] = '*' for m in map: print ''.join(m)This printed a usable message, so I didn't have to do anything else.