General Discussions

Discuss any topics that are not product-specific here.

Advent of Code 2022 Day 13 (BaseA Style)

AlteryxCommunityTeam
Alteryx Community Team
Alteryx Community Team
Discussion thread for day 13 of the Advent of Code - https://adventofcode.com/2022/day/13
5 REPLIES 5
patrick_digan
17 - Castor
17 - Castor

Phew, finally got past it. I don't like my code one bit, but it got the correct answers so I'm going to stop.

Spoiler
I just looked at each element and figured out what "level" it was and setup up some squirrely logic based on the samples. It worked on the samples and my data, but I'm not sure that it's foolproof...
patrick_digan_0-1670960089930.png

 

clmc9601
13 - Pulsar
13 - Pulsar

Wow, lots of parsing. 

 

Spoiler
I separated each line into its items and calculated the cumulative position of each.

Workflow part 1Workflow part 1Workflow part 2Workflow part 2Workflow part 3Workflow part 3


It was helpful to visualize what was happening once I "stood" the data up comparing the two strings:

Spoiler
Screen Shot 2022-12-13 at 2.18.28 PM.png



SeanAdams
17 - Castor
17 - Castor

This was an interesting one - I really did struggle with interpreting the instructions, but Digan & Dawn helped out!

 

Nice opportunity here to do some sorting algorithms - curious to see how others have solved this!

 

Spoiler
Parse:
The parse phase is very simple - it's just a matter of cleanign out the empty rows and creating pairs.

SeanAdams_0-1672110056390.png

 




Part 1:

At first glance, this looked like it would be best handled by recursive index processing - but luckily this one lent itself to processing as a stream of text rather than having to treat this as recursive sets.

For each pair - look at the current character to decide if this character is a fail; or proof of good sort, or identical so-far.
- Only real complexity here is if you need to replace a number x with [x]
Then iterate through every character until you run out.

SeanAdams_1-1672110142181.png

 






 

The first macro just splits this between the first character of every pair, and the remainder - so that the remainder can be processed in the next round.

 

The second macro looks for things like shorter lists; characters that match etc.    This outputs the fails and the successes and any pairs that need an int x to be repaced by [x]

 

SeanAdams_2-1672110252246.png

 

 

This third macro does exactly that replacement:

SeanAdams_3-1672110410527.png

 

 

 

Putting this all together for part 1:

 

(BTW - I've been using files to make it easier to test these macros)

SeanAdams_4-1672110491069.png

 

 

Part 2:

Part 2 is just a sort on part 1.    So if you consider that part 1 is a > operator - then you can do a simple bubble sort by running part 1 multiple times.

 

 

top level:

SeanAdams_5-1672110575074.png

 

 

 

The first level of this sort takes advantage of the fact that Alteryx works in sets.    So the first time it compares the pairs of rows starting from row 1.    If any comparison fails, then it switches the order.

Then it does the same but skips row 1 (i.e. instead of comparing 1 &2; and 3&4 - instead it compares 2&3; 4&5)

 

Then does this in a loop until no rows are being re-ordered by the sort.

 

SeanAdams_6-1672110762484.png

Each of these macros is just part 1 essentially:

SeanAdams_7-1672110854830.png

 

 

 

 

Pang_Hee_Choy
12 - Quasar
Spoiler
part1:

compare line by line,
if either one is "[" and another is int, then add backet and compare one to one.
PairSub-PairTextIDdata
111[
1121
113]
2211

PairSub-PairTextIDdata
111[
1121
113]
220.9[
2211
221.1]


else,
compare it and return result and stop comparing:
Pang_Hee_Choy_1-1672723715299.png

part 2:
Pang_Hee_Choy_0-1672723665364.png

get 3 digit column via regex,
sort all 3 columns and you will get the answer.

AkimasaKajitani
17 - Castor
17 - Castor

Finally done(this is my last challenge).

 

 

Spoiler
The sample data is too simple more than input data. Through many trial and error, I have created an algorithm that is faithful to the problem statement.

The acctually procedure is as fellows.
If there are the combination of int and list, I add the blancket until it runs out. After that, I compare the numbers as shown below.

 - If the left side is smaller, the comparison ends with the Flag set to -1 (if the previous Flag is -1, it is brought back and no further comparison is made).
 - If the right side is larger, the comparison ends with Flag 1.
 - If the numbers are the same, the comparison continues with Flag 0.
 - If the left side is] and the right side is numeric, the comparison is terminated (the left side is Empty, so the comparison is terminated)
 - If the left is numeric and the right is not, the right is Empty and the comparison ends with Flag 1
 - If left is] and right is [, then Flag -1 and comparison ends
 - If the left is [ and the right is ], then the comparison ends with Flag 1 (the right is Empty and the comparison ends)
 - If none of the above is true, then Null is assumed and nothing is done.

AkimasaKajitani_0-1673163771440.png
Macro for part 1:

AkimasaKajitani_1-1673163791274.png

 

 

 

 

https://github.com/AkimasaKajitani/AdventOfCode/tree/main/2022

 

Labels