alteryx Community

# General Discussions

Discuss a wide range of topics! Questions about the Alteryx Platform should be directed to the appropriate Product discussion forum.

## Advent of Code 2021 Day 7 (BaseA Style)

16 - Nebula

20 REPLIES 20
16 - Nebula

This time went with bruteforce attempt

Spoiler
16 - Nebula
Spoiler
as @cgoodman3 pointed out, part1 was the median and part2 was very close to the mean. I rounded the mean in part 2 normally and it didn't work, so tried +-100 and saw that the answer was just rounded down.

11 - Bolide

First thoughts were "let's think this through, surely there's some analytical way to solve it", second thoughts were, "nah, brute force!"... Eventually went back to the thinking board and got somewhere similar to @patrick_digan

Spoiler
Part 1 was OK, the median.
I was beyond my breadth minimising the function for part 2, so started with the mean, thinking of going a binary search if that didn't work. Then it worked...
I've now seen the Reddit thread, but the explanations go partially over my head (good effort on the paper though 😁)

8 - Asteroid

Here sharing but really here to find a better solution. Did anyone use an optimization algorithm, not just every position?

Spoiler
MacroSolution
14 - Magnetar

finally got it...

Anyone figured out Part 2 without generating rows? I mean, I'm pretty sure it'd work taking account of the mean and the Std. Dev. or some sort of normalization, but couldn't figure it out myself (always too high on the score).

Spoiler

15 - Aurora

Variations on a theme, and took a somewhat brute force approach, and a very mathematical one.

Spoiler
First part was to generate all of the possible horizontal position. While the Reddit posts proved useful, and my first solve did use the median for part 1 and the average (rounded up using ceil) for part 2, I didn't understand why that worked, so I kept at it.

To optimize this, I wanted to eliminate duplicate numbers for the Append fields, and also created a "count how many times each number appears in the list field to be used later.

Once all of the possible horizontal positions were aligned with each unique starting number, I calculated the number of steps (absolute value of the original number - the horizontal position)

For part 1, a summarize tool to add up the total number of steps per horizontal position per unique number. Take the results, multiply each by the number of times each number appears in the data set, summarize again for the total steps per horizontal position and sort ascending

For part 2, need to calculate the cost. This is all about adding consecutive numbers, so the formula of (n/2)*(1+n), where n represents the total number of steps for each number to the horizontal position comes into play.

Helping Sigal (my eldest) study for the SHSATs (NYC specialized high school entrance test) actually gave me the formula I needed to solve this one with a simple row by row, math approach.

18 - Pollux

Triangle numbers for the tool golf win

Spoiler
Calculated both the fuel and triangle fuel cost in the single formula tool

Dan

17 - Castor

Who knew there was so much controversy about crab movement!

Spoiler
Recipe:
- Stripped the data down into unique rows
- For each crab - generate all the target position candidates (yes - brute force)
- Then work out the cost - for the cost of the second one use the formula n* (n+1)/2 where n is the distance (that's the formula for this series)
... only realised afterwards that you can figure out the correct target spot using the median

8 - Asteroid

I just know I could have done this with a formula but my brain wouldn't compute

Spoiler

8 - Asteroid

Hmmm, I see a lot of solutions with "generate rows".  Didn't even occur to me to try that.  I only considered aligning to a position that at least one crab started at (634 distinct positions to start).  Used those 634 positions as the control parameters into a batch macro.  Part 1 was easy - distance/fuel = number of moves.  Part 2 wasn't horrendous - as another stated, just (moves/2)*(1+moves).

Spoiler