Skip to content

Instantly share code, notes, and snippets.

@mjgpy3
Created January 19, 2026 02:56
Show Gist options
  • Select an option

  • Save mjgpy3/ada25e3a86652b06554ed7392f26e37a to your computer and use it in GitHub Desktop.

Select an option

Save mjgpy3/ada25e3a86652b06554ed7392f26e37a to your computer and use it in GitHub Desktop.
Advent of Code 2015, Day 1, Part 1 in North
\ Small example filename to the stack
"./d1.txt"
\ Read the file (as string) to stack
read-file
\ Define custom factor
\ Input: count char*
\ Output: [count, "\n"]
: final-floor
\ Done if we only have count and newline char
[ab]? if done
\ Swap top two
[ab*]->[ba*]
\ Is top character a close-paren? (No popping here because it's a pattern)
")" [aa*]?
\ Remove the character we pushed for the check
[bivc*]->[bcv*]
\ Decrement count if they're the same
if decr
\ Swap count and paren again
[ab*]->[ba*]
\ If paren is open paren, increment (`=` check pops)
"(" = if incr
\ Recurse
again
;
\ Put each character of the string onto the stack as a single-char string
splat-string
\ Our starting floor is 0
0
\ Invoke user-defined factor
final-floor
\ Fail if we don't get back the expected floor
-3 = assert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment