Introduction
The Parsons code is just a simple way to describe pitch variations in a piece of music, whether a note is higher or lower than the previous one.
Even if you suck at remembering tunes, you can still pretty much remember if a note goes up or down, thus the Parsons code can help you to identify a music using a search engine.
Description
Each variation is represented by a single character, which is one of the following:
R
if the note is the same than the previous one (stands for "Repeat")U
if the note is higher than the previous one (stands for "Up")D
if the note is lower than the previous one (stands for "Down")
The initial note is written as *
.
Example
Here is an example of Parsons code (beginning of "Ode to Joy"):
*RUURDDDDRUURDR
You can actually visualize it, like this:
*-*
/ \
* *
/ \
*-* * *-*
\ / \
* * *-*
\ /
*-*
We'll call that a contour from now on.
The rules for drawing such countours are considered self-explained by the above example.
Challenge
Now comes the real challenge.
Write a program that, given a contour as input, outputs its corresponding Parsons code.
You are not asked to draw the contour, but the opposite actually.
From the contour, find the original Parsons code.
Rules
- The usual rules for code golfing apply
- The shortest program in number of bytes wins
- The input is a contour, and the output shall be a valid Parsons code
- Details about extra whitespace for the input are irrelevant, do whatever works best for you
- You are not allowed to hardcode, one way or another, parts of the output and / or the program using extra whitespace because of the previous rule
Notes
- This might be useful for testing
- The corresponding Parsons code for
*
is*
- An empty string is not a valid contour
- A Parsons code always starts with
*
*
which doesn't do anything? \$\endgroup\$*
? Nope. It should print*
I suppose. I'll add this corner case. \$\endgroup\$*
. Always. \$\endgroup\$