# Advent of Code 2019 - Day 12

Note: This topic is to talk about Day 12 of the Advent of Code 2019.

There is a private leaderboard for elixirforum members. You can join it by following this link and entering the following code:

`39276-eeb74f9a`

1 Like

Fun, but tricky!

Here is my solution.

2 Likes

Just starting to read the instructions, sound tricky indeed.
Is there a typo in applied velocity example? I believe new x should be 3

1 Like

No, it seems to be correct.

Adding 1 and -2 gives -1. Did you try to subtract -2 from 1?

2 Likes

Replying to myself: x velocity is `-2` and not simply `2`

Itâ€™s going to be tough

1 Like

Part 2 was tough, but I enjoyed it!

I thought I was being clever by walking forward and backward at the same time, but that still took too long.

4 Likes

This is my solution. Takes about 15sec for the second part. Iâ€™m not doing it very efficiently since Iâ€™m computing per-dimension cycle from scratch, so I have to do three large passes, when I could solve everything in one. I should probably also replace the stream-based logic with `Enum.reduce_while` or a recursion. But I was too lazy for that, and this produced the result within a â€śreasonableâ€ť time.

4 Likes

I couldnâ€™t figure out part 2 on my own, the puzzle title made me read up on the N-Body Problem, which made me .

After a couple hours of spinning my wheels (and my computerâ€™s fans), I went looking for the tiniest hint (not spoiler/solution) I could find, which I ended up getting from this post from reddit.

Once I got the basic idea, it took just a couple minutes to code up a solution. And that gave me an answer in about 1 second. Sheesh.

My eventual part 2 solution

2 Likes

I didnâ€™t figure out the trick myself. Oh well.

1 Like

My solution for today, sadly I got spoiled for part2, but I donâ€™t think Iâ€™d have come up with the solution by myself anyways

2 Likes

Here is mine. Like many people here, I also required a hint for part 2, so feeling a little stupid. But after that had no problems and the program runs under 1 second.

3 Likes

I havenâ€™t been spoiled until now â€¦ but I didnâ€™t find the solution either

2 Likes

Part 2 was clearly one of the most intimidating problems to me this year. They dressed it up in fancy clothes with a big name and I imagined it to be worst than it was.
2 Likes

After some failed attempts, I realized that it requires seeing the problem in a different view point. Brute force would not work anymore. I didnâ€™t find the solution immediately. It was frustrating but I let it go.

When I had time this evening, I read the data carefully once again, and thought, maybe I can try separating their positions and velocities of 3D into three groups of 1D data, that would significantly lower the pressure.

So I took it a try and fortunately it worked!

Hereâ€™s the solution I end up with. Iâ€™m so glad I learned this new pattern.

BTW. It finished part 2 in 580ms on my laptop. Not bad.

3 Likes

I had to get a hint about looking at each component of position/vector independently. Then it was relatively easy.

My solution

1 Like

I did it !!!

Iâ€™m proud to have figured out the one axis + LCM trick by myself (even if it involved not sleeping anymore after 5AM, damn brain â€¦ )

I had initially part2 solved in 6 seconds. Running each axis in parallel tasks allowed me to get result in 3 seconds. Then after reading @qhwa code (good job btw ), I simplified my data structure and switched from a map of structs to an array of tuples.

Part2 is now running in 800ms , my code: https://github.com/cblavier/advent/tree/master/lib/2019/day12

Iâ€™m one day late now â€¦

2 Likes