Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Welcome to the AdventOfCodeGolf wiki!
Let's golf Advent of Code!
Standard loopholes are forbidden. Languages made up specifically to solve the problems as a built in are forbidden.
I: Read number
E: Skip if not End-Of-File
h: Print number and halt
+: Add top two numbers on stack
The Gol><> engine is a cycling box, so the pointer swims back in front after it goes out of bounds.
Program hits mirrors and wraps to line 2.
While loop which reads
Int values and if
0. When the loop ends it is like this:
[1 n1 n2 n3 ... nlast 0].
&Pop the 0 and store it into GLOBAL
Wrap around, hit the two mirrors to wrap to line 1. We are on line 1,
[nlast ... n2 n1 1],
~remove 1 at top, set
Teleporter (equal to while loop but easier to explain), this is the final loop with
[nlast ... n2 n1]. For convenience I will hide all values at
[nlast ... n2, but they are there
(Repeat) Start of loop:
:copy top value,
+adds them so now we have:
[... n n+&],
:© it and store the copy to GLOBAL.
ggets a value in our codebox, but since we have a -1 which is outside the range of our code we can be sure that no values exist by default and we're using it as our infinitely sized array to look at what the command at
(n+&, -1)is. Obviously this is 0 (for blank) at first.
qskips the next two commands unless the top value is true.
Our stack is now
[... n] again after
q consumed the condition check and the remaining code is
} rotate the stack around so we can look at the next value next time, our stack is now
[n1 nlast ... n3 n2].
1&:&m Puts in 1, GLOBAL and -1 into the top of the stack,
p consumes them and puts 1 in
(GLOBAL, -1) so the next time we look at this we will get 1 (instead of blank).
t Jump back to teleporter. Eventually we will look up a position of the codebox that is set at
(n+&, -1), which executes
&h - take and print GLOBAL, then halt