This one was much nicer than yesterdays.
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
An easier part 2, which helps when you build out the logic for part 1
I won't take my automatic syntax checkers for granted anymore!
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.
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
Like others have said, I gained a whole new appreciation for automated syntax error detection
I took Brute force approach.
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
https://github.com/AkimasaKajitani/AdventOfCode
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
The push / pop / flush are controlled by conditions that disable the containers - similar to @cgoodman3 's macro for the input picker for these challenges.
Stacks Я Us
Dan