Towers of DC .:.
DC is a reversePolish calculator REPL that is available on most Linux distributions. In reversePolish notation, you can push values to a stack and then pop those values back off to perform operations, pushing the result back. For example, a minimal DC program to prompt for two inputs, add them, and print the result looks like this:
??+pq

?
: Prompt for input 
+
: Pop two values, add them, and push the result 
p
: Print the top value without popping it 
q
: Quit DC
One of the more interesting features of DC is its system of registers, which each hold a stack of numbers. Each register is named with a single ASCII character. The command SA
moves the top value in the main stack to the top of stack A, and the command LA
moves the top value from stack A to the top of the main stack. Thus, SALA
is a noop, and LASB
moves the top value from stack A to the top of stack B.
Imagine a variant of DC where the contents of a stack (including the main stack) must meet the limitations of the game "Towers of Hanoi," to wit: No number in a stack may be larger than the number below it in the stack. In this variation, 4 3+pq
is a valid program, but 3 4+pq
is not. Also notice that the program LALA
is only valid if the top two values in stack A are equal.
As a further limitation, imagine that there are only four stacks available for use: a, b, c, and the main stack.
Write a program that, given a positive integer n, will output a script for this limited version of DC that copies the top n values from stack a to stack c, preserving their order.
For example, a valid solution for n=3 would be:
LaScLaSbLcSbLaScLbSaLbScLaSc
Another valid solution for n=3 that abuses the input and output radices would be:
LaiLaoLaScOScISc
Your score is the sum of the length of your program plus the length of its output for n=5.
0 comment threads