# AoC Day 10: The Stars Align

### Ryan Palo ・1 min read

Advent of Code (26 Part Series)

1) AoC Day 1: Chronal Calibration
2) AoC Day 2: Inventory Management System
3 ... 24
3) AoC Day 3: No Matter How You Slice It
4) AoC Day 4: Repose Record
5) AoC Day 5: Alchemical Reduction
6) AoC Day 6: Chronal Coordinates
7) AoC Day 7: The Sum of Its Parts
8) AoC Day 8: Memory Maneuver (Placeholder)
9) AoC Day 9: Marble Mania
10) AoC Day 10: The Stars Align
11) AoC Day 11: Chronal Charge
12) AoC Day 12: Subterranean Sustainability
13) AoC Day 13: Mine Cart Madness
14) AoC Day 14: Chocolate Charts
15) AoC Day 15: Beverage Bandits
16) AoC Day 16: Chronal Classification
17) AoC Day 17: Reservoir Research
18) AoC Day 18: Settlers of The North Pole
19) AoC Day 19: Go With the Flow
20) AoC Day 20: A Regular Map
21) AoC Day 21: Chronal Conversion
22) AoC Day 22: Mode Maze
23) AoC Day 23: Experimental Emergency Teleportation
24) AoC Day 24: Immune System Simulator 20XX
25) AoC Day 25: Four-Dimensional Adventure
26) Advent of Code Wrap-Up

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.

Advent of Code (26 Part Series)

1) AoC Day 1: Chronal Calibration
2) AoC Day 2: Inventory Management System
3 ... 24
3) AoC Day 3: No Matter How You Slice It
4) AoC Day 4: Repose Record
5) AoC Day 5: Alchemical Reduction
6) AoC Day 6: Chronal Coordinates
7) AoC Day 7: The Sum of Its Parts
8) AoC Day 8: Memory Maneuver (Placeholder)
9) AoC Day 9: Marble Mania
10) AoC Day 10: The Stars Align
11) AoC Day 11: Chronal Charge
12) AoC Day 12: Subterranean Sustainability
13) AoC Day 13: Mine Cart Madness
14) AoC Day 14: Chocolate Charts
15) AoC Day 15: Beverage Bandits
16) AoC Day 16: Chronal Classification
17) AoC Day 17: Reservoir Research
18) AoC Day 18: Settlers of The North Pole
19) AoC Day 19: Go With the Flow
20) AoC Day 20: A Regular Map
21) AoC Day 21: Chronal Conversion
22) AoC Day 22: Mode Maze
23) AoC Day 23: Experimental Emergency Teleportation
24) AoC Day 24: Immune System Simulator 20XX
25) AoC Day 25: Four-Dimensional Adventure
26) Advent of Code Wrap-Up

Classic DEV Post from Jun 20

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.phpI 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.

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

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.

my solution here 😃 thanks for your suggestions

it's coded in Python. it uses vectorization with numpy ndarrays

positions_nda += velocities_nda * iterationsIn order to find the instant for

points of lightalignment, it usesminimizefromscipy.optimizemodule,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!