Discussion thread for day 9 of the Advent of Code : https://adventofcode.com/2020/day/9
Time for a workflow constant (number of rows to look back) to allow for some testing.
I took the iterative route for part one and brute force for part two, which was not fast at all. Interested in seeing the other (read: quicker) solves.
iterative macro
Here's me. I found part 2 easier to set up than part 1, maybe I'd just woken up a bit.
My solution! Not as thrilling as Day 8 (dare I say I was even a bit disappointed to have mentally prepped myself for Intcode V2, just to have today's challenge NOT be a repeat of Day 8??)... but was still able to solve with a pair of iterative macros and only a minor amount of brute force in testing them...
Iterative Macro for Part 1: General gist of it is to take the first 25 rows, find all the valid combinations of record pairs, add them up, then compare value to the 26th row. Built in logic at the end to remove first record for each iteration, but also to escape out of the iterative macro once a match was *not* found (so I don't actually have to iterate through all possible iterations and can stop once my objective is reached).
Cheers!
NJ
https://github.com/AlteryxNJ/AdventOfCode_2020
@jdunkerley79 that's a very elegant solution to part 2 without exploding the number of records 👏
I find with this advent that because the data sets are never very large we can take liberties with memory usage to crank out an answer but its cool to see a solution there that would scale to much larger data sets.
Still feeling quite brute forcey! Nice to not spend hours on today's though...
Generate all for part 1Iterative macro for part 2 which still ran <6 seconds so not horrible
Not too happy with my solution today...
Pretty happy with my results today. While I did use iterative macros for both parts it runs about 40 seconds. Channeled the use of the Multi-Row Formula from @NicoleJohnson and @NedHarding on Part 8 to generate the solutions for my 9a iterative macro. Stir in a little parsing and it all worked (after period of frustration when I didn't set the Multi-Field formula to a large enough size).
Day 9!
Today I made Iterative macro, too.
I'd like to learn Non-Iterative version by anyone's workflow.
Part1 Iterative Macro:
Part2 Iterative Macro:
But It takes less than a minute, so I think no problem.
As anonymous user #1105310
Fun problem... Again no macros - but I did cheat and use Alteryx to generate a super long expression for a multi-field formula for part 1. Without adding the recordID I needed for Part2, part1 has a (cheater) golf score of 3. Part2 looks like almost exactly the same solution as @jdunkerley79
https://github.com/NedHarding/Advent2020
Bit of data explosion never hurt anyone 🙂
Really interesting to see these non-macro alternatives and that they seem to be faster computationally too - enjoying these and learning a ton!
Non-macro part 1 and iterative part 2. Runs in 4.4 seconds non-Amped and errors in Amp and 3.4 in Amp.
The first time I tried it in Amp, the logic in my macro failed because it implicitly assumed that the records in the iterative input wouldn't change order between iterations. It's technically not between iterations, but in the tools that prepare the records to be sent out the iterative output. The solution was to add a Sort tool before the multi-row.
+1 Amp knowledge
Dan
A no macro solution with generate rows creating the data.
Cleaner than I expected, especially for the part 2 macro !
Definitely not winning on tool golf, but my speed is on point. Or on fleek as my 18 year old niece tells me I should be saying.
1.7 seconds.
Still going with no macrosTop flow generates all possibilities of number sums that could be used. Middle flow generates just the ones that will be used. These are joined together. Any set of numbers that doesn't find a match is output.Second part took a bit more thought. Didn't want to generate all combos of numbers, so tried out different looks at the running total. Turns out that subtracting the number from the running total gets you the segment of comparison.
Loads of generate rows tools got the job done. Would be lovely to feed a measure into the sample tool, which was more performant for me than filters,, to make this totally dynamic.