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

jdunkerley79
16 - Nebula
16 - Nebula

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

 

elves-main-jc-211123.png

6 REPLIES 6
LiuZhang
8 - Asteroid
Spoiler
16 - 1 unsolved.png16 - 2 unsolved.png

Stuck on part 1, don't know why it doesn't work.

For most of the sample code given, it works. Though for code with more than 2 sub_packet split, I will need to manually add more macro. (As my data has only one split, so it should work.)

 

General idea is to handle string as instructed, use substring to progress in series.

dsmdavid
11 - Bolide

Just took 2 hours to read the prompt. Painful iterative. Wanted to keep track of the hierarchy but those packets that contain X number of packets are a pain...

Spoiler
inner iterative. The workflow works with all the example inputs. With the actual input, it fails. Somewhere. But gets close enough -- after some fruitless debugging I thought there were just one or two packets missing, and luckily it was true as the output was just 7 points shorter (some faith and some trial and error proved that 😅).

dsmdavid_1-1639766382908.png

The hierarchy is all messed up (stored in recordID), so no way I can tackle part 2 as it stands... number_dec 8 RecordID 1.3.2.4.9.2.1.2.2.1.9.5.1.5.2.1.1.3.1.1.1.1.1.1.2.4.2.1.2.1.2.1.1.3.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1 version 0 type 4 children 



 

 

 

patrick_digan
16 - Nebula
16 - Nebula

phew, finally got part 2 to work.

Spoiler
After reading (and rereading) the instructions, I finally understood what was going on. 

Workflow:
patrick_digan_0-1639787644352.png


Part 1 macro wasn't too complex. Regex was a big help on the getting the literal values. TIL that you need to put a + in front of your string if it's exactly 32 characters:

patrick_digan_4-1639787977136.pngpatrick_digan_1-1639787718780.png

Part 2 macro was much worse and took some refactoring after it worked on the samples but not my data. Basically I process as many subpackets as possible and then try again.

 


 

patrick_digan_2-1639787786500.png

 

SeanAdams
17 - Castor
17 - Castor

WOW - that took a day to figure out an approach and to execute.     To be fair to the problem, I'm not a speed-developer like @NicoleJohnson .    This is another one of these problems that would be much easier to solve in a single pass using recursion, but Alteryx doesn't have this yet.  

 

Fun part of this was that I got to use something I learned a while ago from @patrick_digan - the Dynamic Replace, and it's ability to create code that can be created & executed dynamically.

 

 

Spoiler
OK - here's the recipe I followed:
Step 1: Hex to Bin - did this in a separate macro
Step 2: Lex out the operators into a list - i.e. convert the binary stream into a list of operators and literal values
Step 3: iteratively process this list of operators, working from the bottom of the tree upwards (sorta like working from the inner-most brackets outwards)
- The way I did this was to start at the bottom of the tree - for example look for things like Greater Than followed by 2 literals)
- Work out the result of this leaf
- Replace all the rows that were part of this calculation into just 1 row which is a literal
- Repeat
Step 3a: 
- to do the "work out the result" piece - dynamically created a quick formula - and then used Dynamic Replace to execute it.

For example:
Operator Sum
    Operator Literal 3
    Operator GreaterThan
         Operator Literal 15
         Operator Literal 3
    Operator Literal 2

The italic bits now resolve down to a single line which is a literal
Operator Sum
    Operator Literal 3
    Operator Literal 1
    Operator Literal 2

Then you do Sum and this collapses to 
Operator Literal 6

which is the answer.


Main flow:

SeanAdams_0-1640208701345.png

 


Then the lexer 
SeanAdams_1-1640208741529.png


Then the part that iteratively solves the tree

SeanAdams_2-1640208797314.png

 

And finally the piece that executes the calculations

SeanAdams_3-1640208864361.png

 

 






 

 

Pang_Hee_Choy
10 - Fireball

Spent 3 week (everyday 3 hours though)... to complete this. 

 

Spoiler
Part 1 is completed accidently...i just try and error.

but to complete part two, take of 90% of time to built the nice Tree for numbering, operator and Len. look good but quite useless 😅

luckily the length set is exactly same without any dispose digit, if not it will take 2 more week.
Pang_Hee_Choy_0-1641439686769.png


with this nice tree, I can do part 2 easily.

thank @SeanAdams for the workflow. so that i can realise i very close to the correct answer.
thank @patrick_digan for mention the sign issue in BintoInt conversion, just a steps to the correct answer.
i was thought a ABS function will solve the issue.

Pang_Hee_Choy_2-1641440008784.png

 




 

 

SeanAdams
17 - Castor
17 - Castor

I'm with you on this @Pang_Hee_Choy - I'm still crunching my way through the last 3 AOC challenges.