[Question]
  [
# 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 *"**R**epeat"*)
* `U` if the note is **higher** than the previous one (stands for *"**U**p"*)
* `D` if the note is **lower** than the previous one (stands for *"**D**own"*)
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**](http://www.musipedia.org/melodic_contour.html)
* The corresponding Parsons code for `*` is `*`
* An empty string is not a valid contour
* A Parsons code **always** starts with `*`
  
[Answer]
# CJam, 21 bytes
```
qN/:.e>(o2%:i"DRXU"f=
```
Fold the lines (`:`) by vectorizing (`.`) a character-wise maximum operation `e>`. Since there is only one non-space character in each column, this one will be the result, as space has a smaller ASCII code than all printable non-space characters.
Unshift and print the first asterisk `(o`, then map every other (`2%`) remaining char to `UDR` using modular indexing.
## Old solution (29 bytes)
```
'*qN/z2%'*f#0+2ew);::-"RDU"f=
```
`qN/` gets input lines. `z` transposes this character matrix. `2%` drops every odd row. `'*f#` finds the index of the asterisk in each row. `0+2ew);` gets all successive pairs of indices. `::-` computes their differences, and `"RDU"f=` maps them to letters (via modular indexing: `0 → R`, `2 → U`, `-2 ≡ 1 → D`). The leading `'*` prepends the asterisk.
**EDIT**: I changed `2ew` to `0+2ew);` to work around CJam not handling `ew` (successive slices) on lists that are too short. This makes the code work for the input string `*`.
[Try it here](http://cjam.aditsu.net/#code=%27*qN%2Fz2%25%27*f%232ew%3A%3A-%22RDU%22f%3D&input=%20%20%20%20%20%20*-*%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%2F%20%20%20%5C%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20*%20%20%20%20%20*%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%2F%20%20%20%20%20%20%20%5C%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0A*-*%20%20%20%20%20%20%20%20%20*%20%20%20%20%20%20%20%20%20*-*%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%5C%20%20%20%20%20%20%20%2F%20%20%20%5C%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20*%20%20%20%20%20*%20%20%20%20%20*-*%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5C%20%20%20%2F%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20*-*%20%20%20%20%20%20%20%20%20%20), or watch it in action:
```
              ![](https://i.stack.imgur.com/Joojm.gif)
```
[Answer]
# Pyth - ~~28~~ ~~25~~ ~~27~~ 25 bytes
*2 byes saved thanks to @Jakube.*
```
s+\*@L"RDU"-VFtBxR\*%2C.z
```
[Try it online here](http://pyth.herokuapp.com/?code=s%2B%5C%2a%40L%22RDU%22-VFtBxR%5C%2a%252C.z&input=++++++%2a-%2a++++++++++++++++++++%0A+++++%2F+++%5C+++++++++++++++++++%0A++++%2a+++++%2a++++++++++++++++++%0A+++%2F+++++++%5C+++++++++++++++++%0A%2a-%2a+++++++++%2a+++++++++%2a-%2a++++%0A+++++++++++++%5C+++++++%2F+++%5C+++%0A++++++++++++++%2a+++++%2a+++++%2a-%2a%0A+++++++++++++++%5C+++%2F+++++++++%0A++++++++++++++++%2a-%2a++++++++++&debug=0).
[Answer]
# Python 3, ~~129~~ ~~108~~ ~~98~~ 86 bytes
There are probably several ways to golf this, but I rather like that I got it all down to one line.
**Edit:** Now using `''.translate()`
**Edit:** With many thanks to [wnnmaw](https://codegolf.stackexchange.com/users/30170/wnnmaw).
**Edit:** I changed the input format to an array of strings instead of a newline-separated string to save bytes. Also, in the last edit, I mixed up `U` and `R`, so I fixed that.
```
lambda a:'*'+"".join(('UR'[j<'/']+'D')[j>'/']for l in zip(*a)for j in l if j in'-/\\')
```
Input must be an array of strings. For the example above, this looks something like:
```
["      *-*                    ","     /   \                   ","    *     *                  ","   /       \                 ","*-*         *         *-*    ","             \       /   \   ","              *     *     *-*","               \   /         ","                *-*          "]
```
Ungolfed:
```
def f(a):
    s = ''
    for c in zip(*a):           # transpose
        for d in c:             # for each letter in column c
            if e in "-/\\":     # if that letter is either -,/,\
                if e < '/':     # if < '/' (same as if == '-')
                    s += "R"
                elif e > '/':   # if > '/' (same as if == '\')
                    s += "D"
                else:           # if == '/'
                    s += "U"
        return "*" + s          # in the code we ''.join() it all together
                                # in this ungolfing, we add to an empty string
```
[Answer]
# Ruby, 87 bytes
Requires trailing spaces in the input so that all lines are the same length.
```
$><<?*+$<.readlines.map(&:chars).transpose.join.gsub(/./,{?-=>:R,?/=>:U,?\\=>:D}).strip
```
[Answer]
# Japt, 38 bytes ~~40 41 45 46 48~~
*Saved 2 bytes thanks to @ETHproductions*
```
'*+U·y £Yu ?"RUD"g1+(XrS c -47 g):P} q
```
If there was a trim command this would be only 38 bytes ;-; will add explanation when I'm done golfing. The `:P` is not the program trying to be funny, it's actually the program ignoring characters that aren't important.
[Try it online](http://ethproductions.github.io/japt?v=master&code=JyorVbd5IG1AWXUgPyJSVUQiZyhYclNQIGMgLTQ3IGcgKzEgOlB9IHE=&input=IiAgICAgICotKiAgICAgICAgICAgICAgICAgICAgCiAgICAgLyAgIFwgICAgICAgICAgICAgICAgICAgCiAgICAqICAgICAqICAgICAgICAgICAgICAgICAgCiAgIC8gICAgICAgXCAgICAgICAgICAgICAgICAgCiotKiAgICAgICAgICogICAgICAgICAqLSogICAgCiAgICAgICAgICAgICBcICAgICAgIC8gICBcICAgCiAgICAgICAgICAgICAgKiAgICAgKiAgICAgKi0qCiAgICAgICAgICAgICAgIFwgICAvICAgICAgICAgCiAgICAgICAgICAgICAgICAqLSogICAgICAgICAgIg==)
[Answer]
## Haskell, 89 bytes
```
import Data.List
m '/'="U"
m '-'="R"
m '\\'="D"
m _=""
('*':).(>>=(>>=m)).transpose.lines
```
Usage example:
```
*Main> ('*':).(>>=(>>=m)).transpose.lines $ "      *-*                    \n     /   \\                   \n    *     *                  \n   /       \\                 \n*-*         *         *-*    \n             \\       /   \\   \n              *     *     *-*\n               \\   /         \n                *-*          "
"*RUURDDDDRUURDR"
*Main> ('*':).(>>=(>>=m)).transpose.lines $ "*"
"*"
```
Transpose the input and replace the characters `/`/`-`/`\` with singleton strings `"U"`/`"R"`/`"D"`. All other chars are replaced by empty strings `""`, which later disappear by concatenating everything. Finally, prepend the asterisk `*`.
[Answer]
## Mathematica, 103 bytes
```
"*"<>(Differences@Position[Thread@Characters@StringSplit[#,"
"],"*"][[;;,2]]/.{-2->"U",0->"R",2->"D"})&
```
Quite short, considering that this is a string-processing challenge.
[Answer]
# JavaScript (ES6) 90
An anonymous function. It scans the input string char by char, taking into accout the position in the current line. Doing this, it builds an output array subsituting `U D R` for `/ \ -` at the right place
```
c=>[...c].map(c=>c>'*'?t[i++]=c>'/'?'D':c<'/'?'R':'U':c<' '?i=0:++i,t=['*'],i=0)&&t.join``
```
[Answer]
# Matlab, 62 bytes
```
r=@(s)[85-(s<14)*3-(s>59)*17,''];@(p)r(sum(p(:,2:2:end)-32))
```
This requires the input to be a rectangular (same number of characters in each row). E.g.
```
    ['      *-*                    ';    '     /   \                   ';    '    *     *                  ';    '   /       \                 ';    '*-*         *         *-*    ';    '             \       /   \   ';    '              *     *     *-*';    '               \   /         ';    '                *-*          '];
```
### Explanation
```
sum(p(:,2:2:end)-32)        % exctract every second column, substract 32 (spaces->zeros) 
                            % and sum column wise (results in a vector of 3 different values)
[85-(s<14)*3-(s>59)*17,'']  % map each of the values to the corresponding value of the letter and convert back to characters
```
]