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

Towers of DC .:.

+3
−0

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

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

0 answers

Sign up to answer this question »