Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

71%
+3 −0
Challenges Towers of DC .:.

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...

0 answers  ·  posted 4mo ago by Andrew Ray‭  ·  edited 4mo ago by trichoplax‭

#2: Post edited by user avatar trichoplax‭ · 2024-07-22T14:08:47Z (4 months ago)
Add alternative scoring tag
#1: Initial revision by user avatar Andrew Ray‭ · 2024-07-22T13:40:50Z (4 months ago)
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.