General Discussions

Discuss any topics that are not product-specific here.

Advent of Code 2021 Day 10 (BaseA Style)

jdunkerley79
ACE Emeritus
ACE Emeritus

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

 

 
 

Mini-Submarines _ The Ultimate Yacht Toy.jpg

14 REPLIES 14
bflick
8 - Asteroid

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
cgoodman3
14 - Magnetar
14 - Magnetar

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

 

Spoiler
cgoodman3_0-1639118177315.png

 

Chris
Check out my collaboration with fellow ACE Joshua Burkhow at AlterTricks.com
clmc9601
13 - Pulsar
13 - Pulsar

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.

Screen Shot 2021-12-10 at 12.25.42 AM.pngScreen Shot 2021-12-10 at 12.26.31 AM.png
afv2688
16 - Nebula
16 - Nebula

Easier today than yesterday

 

Spoiler
Untitled.png
estherb47
15 - Aurora
15 - Aurora

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

 

estherb47_0-1639161265154.png

 

 

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

starkey
7 - Meteor

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

 

Spoiler
starkey_0-1639176018397.png

 

 

AkimasaKajitani
17 - Castor
17 - Castor

I took Brute force approach.

 

Spoiler
AkimasaKajitani_0-1639192825558.png
AkimasaKajitani_1-1639192837762.png

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

 

SeanAdams
17 - Castor
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:
SeanAdams_0-1639298917689.png

 


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

SeanAdams_2-1639299020444.png

 


 

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



 

danilang
19 - Altair
19 - Altair

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.
danilang_0-1639314557158.png 

 Dan

Labels