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.
Each variation is represented by a single character, which is one of the following:
Rif the note is the same than the previous one (stands for "Repeat")
Uif the note is higher than the previous one (stands for "Up")
Dif the note is lower than the previous one (stands for "Down")
The initial note is written as
Here is an example of Parsons code (beginning of "Ode to Joy"):
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.
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.
- 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
- This might be useful for testing
- The corresponding Parsons code for
- An empty string is not a valid contour
- A Parsons code always starts with