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 21 (BaseA Style)

jdunkerley79
16 - Nebula
16 - Nebula

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

 

 

istockphoto-473046237-640x640.jpg

8 REPLIES 8
patrick_digan
16 - Nebula
16 - Nebula

Phew, only 4 more to go! Fun part 2 today.

Spoiler
For part 1 I just used multi-row formulas to calculate everything. For part 2, I had an iterative macro and summed all the different possibilities. There are 3 dice with 3 possibilities, so 27 different possibilities. When you sum the 3 dice up, there are only 7 different outcomes (3-9) with varying chance. For example  there is only 1 way to get a sum of 3 (1-1-1) but 3 ways to get a sum of 4 (1-1-2 , 1-2-1 , 2-1-1). 

patrick_digan_0-1640090167588.png

Part 2 macro:
patrick_digan_1-1640090198688.png

 


 

cgoodman3
13 - Pulsar
13 - Pulsar
Spoiler
Another fun challenge
Solved part 1 initially in a spreadsheet as it's an easy one, and I was too lazy too boot up Alteryx while still in bed, so just did it in Google Sheets on my phone, but have now retrospectively solved it with Alteryx

Part 2 took like the lanternfish and polymer days is a case of grouping together the combinations and iterating over that, which leads to a sub-2 second run time.

Workflow
cgoodman3_0-1640099842942.png


Macro for part 2

cgoodman3_1-1640099880874.png

 

Chris
Check out my collaboration with fellow ACE Joshua Burkhow at AlterTricks.com
LiuZhang
8 - Asteroid

Looking for some suggestions, I've checked vs @patrick_digan , the logic is the same, but I cannot figure out what's wrong with my macro. It under-counted a lot of results.

Idea is to iterate through each round, count the combinations.

patrick_digan
16 - Nebula
16 - Nebula

@LiuZhang check your text input in your workflow, I think you put the starting position for player2 into their score.

LiuZhang
8 - Asteroid

Great, thanks.

After 2 hrs constantly changing the formula tool, it's the text input was wrong. The irony of it.

Well, at least today's doable compare to the weekend.

dsmdavid
11 - Bolide

Happily playing golf for part I...only to find out part II... then iterative it was.

Spoiler
dsmdavid_0-1640172633569.png

A similar approach to those above for the grouping. Although a lot less neat

dsmdavid_1-1640172739009.png

For part 1 I went with a generate rows that was fun to build that keeps track of points for players, current position, last_advance, number of rolls.

dsmdavid_2-1640172932006.png

Because of the deterministic dice we know that the first roll is 1+2+3 --> advance 6; the next is 4+5+6 --> 15 == advance 5; 
1+2+3 -->   6 == 6
4+5+6 --> 15 == 5
7+8+9 --> 24 == 4
.....            33 == 3
                 42 == 2
etc, so no need to keep track of the actual numbers, just know that the next turn the marker will advance one square less. 

https://github.com/dsmdavid/AdventCode2021

SeanAdams
17 - Castor
17 - Castor

This was a fun one - and I just got tripped up on a < vs. <= issue - thank you @patrick_digan for posting your full solution so that I could use yours to cross-check and find my error.

 

Spoiler
Recipe is kinda simple:
- Work out the dice throws that happen when you roll 3 die that can be 1-3, and group them by the total sum.
- in other words, 3 occurs once, 4 occurs 3 times etc.
- then take the latest state of your position universes and:
      - Append these dice rolls (to multiply the record count by 7)
      - For the player who is currently taking a turn - add on the dice score and work out the position
      - For the player who is not taking taking a turn, leave as-is
      - multiply the universe count by the dice count
      - Summarise again by the total scores across P1 and P2
      - Then reprocess any where both players have a score less than the threshold - and output any where the player score is >= the threshold (i.e. score of 21)

Main Flow:
SeanAdams_0-1640885667789.png

 

:-) I've included @patrick_digan 's macro that I used to find my error in this.    You can see that it's pretty straighforward.


The Dice Throw:

 


 

Also relatively simple - all the work is done in the formula tool in the middle which updates the scores.
- The main thing that I did differently than @patrick_digan is instead of keeping track of which player's turn it is using a turn flag, I instead looked at the Iteration Number - if the iteration number is even then it's player 1's turn, if it's odd then player 2.  This is done using a mod operator.    Modulus finds the remainder when dividing one number by another.   This is super-common trick in computer science.     Digan's trick (with a simple flag) involves much less computation I'd think
- I put on a parameter for score-ceiling to be able to test with progressively higher score thresholds
- I calculate the dice throws every time which is wasteful - Digan pre-calulated them and used a text input - perhaps a better answer is somewhere in the middle where we pass this in via a static input to the macro
- and the great debate about vertical vs. Horizontal

SeanAdams_3-1640886023459.png

 



Pang_Hee_Choy
10 - Fireball

thanks @patrick_digan again for the workflow. it simple and work well.

 

Spoiler
P1 : generate the list of dices. group and sum it. Join and do the comparation.
Pang_Hee_Choy_0-1642069082837.png

P2: 
i already have idea to do by group as flash fish. but i can't figure how....
thanks patrick once again. it countless time that i referred to your workflow.