On Day 10, the stars are aligning to send us messages. It's not a proper Advent of Code until we've had a vector problem, and I'll be honest that, as I started reading the prompt, I was thinking, "Oh, no problem! Vector math! I'm a mechanical engineer! I love vector math!"
And then.
......................
......................
......................
......................
......#...#..###......
......#...#...#.......
......#...#...#.......
......#####...#.......
......#...#...#.......
......#...#...#.......
......#...#...#.......
......#...#..###......
......................
......................
......................
......................
Head -> Desk.
OK, back to my consistent state of "not sure how we're going to do this." But that's what makes it fun! Right? Right? I'm excited to see your solutions.
Top comments (10)
This is my fastest one yet! May clean up the solution tomorrow, but:
This one was quite easy - just do calculations until all the values are closest together (i.e. check for min height) and then print them to the console. Didn't event have to do anything for part 2 ;)
readFile.php
I also stopped when I noticed that the stars started getting further apart. I wish that had been part of the problem description though, since it's possible for to come up with an input that breaks that assumption.
Just waiting for the smallest constellation could be wrong, I can imagine the lights forming even smaller image after (or before) showing the message. So, I printed all the possibilities fitting to an old-school terminal. In my case, there were three, and one of them contained the message. I printed the time along the way, so I solved both the parts in one go.
This one was quite interesting. Integrating moving points over time is straightforward enough but how do we detect the moment a message appears? I'm going to assume it's at the point in time when the bounding box of all the points is smallest.
First we'll reuse and extend some of the geometric primitives from day 6:
And we'll add a function to get a point's position at any time
t
:We'll solve the problem by iterating over a large period of time and computing the bounding box for the points at each time. Then take the smallest of these bounding boxes:
Then we'll render the points into beautiful ASCII art at that time by building a 2D array of characters and filling in the ones at the right positions:
Part 2 was either disappointing or a relief, depending on your viewpoint, as my part 1 solution already had the answer.
Full code at github.com/neilgall/adventofcode20...
Javascript solution
I had a really hard time with Stack Overflows (I even tried my company's computer to see if it would be better). I even looked at pixel plotting libraries for Node.js.
It took me 1 hour to realize that I would not need to print the whole matrix - but I could just keep processing it until I got it to the smallest height, and then I print it.
However I would only know I got to the smallest height after I'm no longer on the smallest height and then I need to tick the clock just once backwards to get back to the smallest height and print it.
reader.js
10.js
my solution here 😃 thanks for your suggestions
it's coded in Python. it uses vectorization with numpy ndarrays
positions_nda += velocities_nda * iterations
In order to find the instant for points of light alignment, it uses minimize from scipy.optimize module,
This one wasn't as bad as I thought it was going to be -- albeit I did it significantly more manually than they might have hoped. Basically, I just iterated until the stars were reasonably close together (I guessed 30 rows overall range, and it worked out pretty well), and then printed out the sky at each iteration and scrolled through my terminal until I found one that wasn't nonsense. For the second part, I added one line to print the time above each iteration.
Maybe not the most algorithmically performant (lots of nested for-loops), but it did like 20k ticks in less than a second, so probably OK.
A data scientist on my team visualized her solution
Whoah! That's smart! So cool. Thanks for sharing!