Advent of Code - 2019 - Day 3-4

The third problem was a grid puzzle. Two long and twisting wires should be analyzed for
crossings. And the task was to return the crossing nearest to the starting point (and the
crossing with shortest steps from the starting point in part 2). For efficiency reasons
I decided to sacrifice compact code for repeating myself a bit. There is an overlap
between part 1 and part 2, but the solution is basically repeated twice. In the end it
solves the problem for my input in about 20 seconds.

My solution is here - but I am sure it can be done more efficiently…

3 Likes

The fourth problem was about checking integer “passwords” for some somewhat strange properties. The straightforward solution looping over all integers and checking them one by one worked. But it was really slow (upwards of two minutes) - so in the end I decided to use one of the properties (digits must be increasing) to skip over many integers at the same time. This improved the solution a lot, and it now even fits in a single block (5.7M gas) and runs in about half a second.

My solution is here - this is the optimized version where a number of integers are skipped in one step.

With this solution we are in sync - let’s see what tomorrow’s puzzle will bring.

2 Likes

I started out trying to build a parser for the input data, which was a futile endeavor. Finally I used sed to prepare the input data to some degree to make it usable, just a little cheating. The final approach is not very optimized and the code is certainly not nice to look at. I think I overused type definitions after discovering those :slight_smile:

My solution is here

Runtime:

([email protected])81> aefa_sophia_test:run_file("day_03/sophia/2019_day_3.aes", "solve_part_1", []).
20913125 steps / 112276956536 gas / 872499038 reductions / 30282.88ms
Store:
  #{}
1225
([email protected])82> aefa_sophia_test:run_file("day_03/sophia/2019_day_3.aes", "solve_part_2", []).
20915751 steps / 112297988129 gas / 869169875 reductions / 29968.59ms
Store:
  #{}
107036
1 Like

Day 4 was interesting indeed. I figured out the brute-force option quickly, which clocks in at about 3 minutes. Minor improvements were easy but I didn’t get to optimize it to a state comparable with @hanssv yet. Need to move on to day 5 :slight_smile:

My solution is here

1 Like