Advent of Code 2019 - Day 14

Note: This topic is to talk about Day 14 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 puzzle! Spent some time on part 2 before I found the solution (first tried another approach that turned out to be too slow).

Here is my solution.

3 Likes

Loved it very much too :slight_smile:
And I’m proud of the optimization trick I used to solve part2 in about 70ms.

My code: https://github.com/cblavier/advent/tree/master/lib/2019/day14

2 Likes

Here’s my take.

2 Likes

This code is bad, please don’t look (why am I uploading it then?)

2 Likes

Search and optimization on this one! I use an approach that seems different from what has been submitted here so far, based on digraph topological sorting for p1, and then I use both exponential and binary searches for p2.

I got part 1 to run within 2-10ms and part 2 to run within 15-25ms for my input.

Source at https://gist.github.com/ferd/82866a1d80ee539d2c6e9e85e52f10b9

3 Likes

My solution

It was difficult to get all the variables and calculations and updating of surplus register right for part 1.

Part 2 was easy once I realized I could simply binary search.

1 Like

I managed to do it with a very slow code, in a very ugly way. Could someone explain the binary search technique ?

I would understand if for 1 FUEL you have N ORE, but actually creating 1 FUEL extracts N ORE and byproducts that can be reused for the next FUEL …

edit: no, ok, I get, it, it is just that you code to produce 1 FUEL is good, and mine is so slow.

1 Like