Unihedron edited this page Dec 1, 2018 · 5 revisions

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.

Day 1-A: 4 bytes in Gol><> Try it online!

IEh+

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.

Day 1-B: 31 bytes in Gol><> Try it online!

\r~T:&+:&mgq&h}1&:&mpt
\1WIE0|&
  1. Program hits mirrors and wraps to line 2.

  2. Insert 1, begin While loop which reads Int values and if EOF inserts 0. When the loop ends it is like this: [1 n1 n2 n3 ... nlast 0]. & Pop the 0 and store it into GLOBAL

  3. Wrap around, hit the two mirrors to wrap to line 1. We are on line 1, reverse stack [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

  4. (Repeat) Start of loop: [... n], : copy top value, & takes GLOBAL, + adds them so now we have: [... n n+&], :& copy it and store the copy to GLOBAL. m Insert -1, g gets 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. q&h where q skips 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 }1&:&mpt. } 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

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.