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
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
Fun, but tricky!
Here is my solution.
Just starting to read the instructions, sound tricky indeed.
Is there a typo in applied velocity example? I believe new x should be 3
No, it seems to be correct.
Adding 1 and -2 gives -1. Did you try to subtract -2 from 1?
Replying to myself: x velocity is -2
and not simply 2
It’s going to be tough
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.
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.
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.
I didn’t figure out the trick myself. Oh well.
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
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.
Source at https://gist.github.com/ferd/0301e44a7068a067ac4b5434027026e5
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.
I had to get a hint about looking at each component of position/vector independently. Then it was relatively easy.
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 …