Upgrading Server to version 22.1? We’ve enabled the faster AMP engine by default. Read about how these system settings changes might affect you.

2022-05-24 Updates: Login: If you are facing issues with logging in, please try clearing all your cookies or trying another browser. We have a fix being deployed on the evening of 5/25. Email: If you're not seeing emails be delivered from the Community, please check your spam and mark the Community emails as not junk. Thank you for your patience.
alteryx Community

# General Discussions

Discuss any topics that are not product-specific here.

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

ACE Emeritus

14 REPLIES 14
7 - Meteor

This one was much nicer than yesterdays.

Spoiler
Step 1: Tokenize each syntax line into rows
Step 2: Create a monster of a multi-row formula to check if open and closes are correct
Sauce:
Spoiler

IF [Row-1:RecordID] != [RecordID]
THEN
IF [Parse] = "["
THEN "]"
ELSEIF [Parse] = "("
THEN ")"
ELSEIF [Parse] = "<"
THEN ">"
ELSEIF [Parse] = "{"
THEN "}"
ELSE "ERROR"
ENDIF
ELSE

IF [Row-1:Check] = "CORRUPTED" OR [Row-1:Check] = "Stopped"
THEN
IF [Row-1:Check] = "CORRUPTED"
THEN "Stopped"
ELSE "Stopped"
ENDIF
ELSE

IF [Parse] IN ("[","(","<","{")
THEN

IF [Parse] = "["
THEN "]"
ELSEIF [Parse] = "("
THEN ")"
ELSEIF [Parse] = "<"
THEN ">"
ELSEIF [Parse] = "{"
THEN "}"
ELSE "ERROR"
ENDIF
+
[Row-1:Check]
ELSE

IF [Parse] IN ("]",")",">","}")
THEN
IF left([Row-1:Check],1) = [Parse]
THEN right([Row-1:Check],length([Row-1:Check])-1)
ELSE "CORRUPTED"
ENDIF

ELSE "ERROR"
ENDIF
ENDIF
ENDIF
ENDIF

Step 3: Filter for identified corrupted and do the points math
Step 4: Filter for uncorrupted. Tokenize to rows and do the points math
13 - Pulsar

An easier part 2, which helps when you build out the logic for part 1

Spoiler

Chris
Check out my collaboration with fellow ACE Joshua Burkhow at AlterTricks.com
12 - Quasar

I won't take my automatic syntax checkers for granted anymore!

Spoiler
Took me a long time to realize that the "first" invalid characters would not necessarily be the first/outermost in the string but instead on the inside (working outward) of the first chunks.

I used an iterative macro to remove the valid pairs from the string until it found an invalid pair (part 1) or none, meaning an incomplete string (part 2) if there were still characters left.

16 - Nebula

Easier today than yesterday

Spoiler
15 - Aurora

Likely way over par on tool golf, but happy with my solution.

First solve was on graph paper. So far, I've done 3 solves on graph paper before going into Alteryx to get my logic straight. Wanted to avoid another macro (though an iterative would be perfect here) for performance and I have too many macros already.

Spoiler
Multi-Row FTW!

Logic is to build the closing symbol for each opening symbol, adding to the left of the row above so things nest properly.

Once we get to closing symbols in the code, we look if the row above has the correct one in the leftmost position. If it does, then copy that string from above, removing the leftmost character.

If it doesn't match, it's corrupted. If the above row is corrupted, put the word "stop"

I grouped by record id to simplify the ugly IF THEN ELSE in the multirow:

Spoiler

IF [Row-1:Check] IN ("Corrupt","Stop") THEN "Stop"
ELSEIF [Field1] IN ("[","{","<","(") THEN
IF [Field1]="[" THEN "]"
ELSEIF [Field1]="{" THEN "}"
ELSEIF [Field1]="<" THEN ">"
ELSE ")"
ENDIF
+[Row-1:Check]
ELSEIF ([Field1]="]" AND Left([Row-1:Check],1)="]" )
OR ([Field1]="}" AND Left([Row-1:Check],1)="}")
OR ([Field1]=">" AND Left([Row-1:Check],1)=">")
OR ([Field1]=")" AND Left([Row-1:Check],1)=")")
THEN right([Row-1:Check],length([Row-1:Check])-1)

ELSE "Corrupt"

ENDIF

6 - Meteoroid

Like others have said, I gained a whole new appreciation for automated syntax error detection

Spoiler

15 - Aurora

I took Brute force approach.

Spoiler

In iterative macro, I delete the each pair of the blankets (),[],{},<>.
In star1, the first of remaining end blankets are goal.
In star2, replace the start blankets with end blankets and then sort by descending position in each line.

GitHub

17 - Castor

This was a beautiful one - it's a classic problem that you would often use a Stack to solve in compilers

🙂 so I built a little stack process with 3 macros - push; pop; and flush

Spoiler

Fundamentally this is very simple:
- Take each input
- if it's an opening bracket - push it onto the stack
- if it's a closing bracket - pop off the top-most open bracket - if they match then you're good, if not you have an issue
- If you run out of inputs before your stack is empty - then you have incomplete bits.

Main flow:

The main work is done in the Stack Manager (the thing that looks like a colorful stack)

The push / pop / flush are controlled by conditions that disable the containers - similar to @cgoodman3 's macro for the input picker for these challenges.

Full code down below

18 - Pollux

Stacks Я Us

Spoiler
Similar to @estherb47 and @starkey, used a stack like @SeanAdams, but implemented it as a string.  As it parses through the characters, the algorithm builds up the string necessary to close the statement, adding and removing the appropriate closing characters to the start of the closing string as required.  The answer to Part 2 falls out from Part 1 as the closing string remaining after all the characters have been processed.  All tools in Part 2 are just there to calculate the score.

Dan

Labels