Post History
DC is a reverse-Polish calculator REPL that is available on most Linux distributions. In reverse-Polish notation, you can push values to a stack and then pop those values back off to perform operat...
#1: Initial revision
Towers of DC .:.
[DC](https://www.mkssoftware.com/docs/man1/dc.1.asp) is a reverse-Polish calculator REPL that is available on most Linux distributions. In reverse-Polish 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 no-op, 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.
