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)

jdunkerley79
16 - Nebula
16 - Nebula

Discussion thread for day 7 of the Advent of Code - https://adventofcode.com/2021/day/7

 

 
 
 
 

cute-crab-paint-by-number.jpg

20 REPLIES 20
afv2688
16 - Nebula
16 - Nebula

This time went with bruteforce attempt

 

Spoiler
Untitled.png
patrick_digan
16 - Nebula
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.
patrick_digan_0-1638881502711.png

 

dsmdavid
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 😁)

dsmdavid_0-1638884702138.png

 

DataG8
8 - Asteroid

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

Spoiler
MacroMacroSolutionSolution
Aguisande
14 - Magnetar
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
Aguisande_0-1638896970430.png

 

estherb47
15 - Aurora
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. 

estherb47_0-1638923886402.png


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

estherb47_1-1638924081486.png



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.

estherb47_2-1638924265312.png

 

danilang
18 - Pollux
18 - Pollux

Triangle numbers for the tool golf win 

 

Spoiler
Calculated both the fuel and triangle fuel cost in the single formula tool
 danilang_0-1639221313898.png

 

Dan

 

 

SeanAdams
17 - Castor
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 

SeanAdams_0-1639242653147.png

 






caitlynmcintyre
8 - Asteroid

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

 

Spoiler
caitlynmcintyre_0-1639705408856.png

 

Mchappell67
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
Mchappell67_0-1640147066263.png

 

Mchappell67_1-1640147093054.png