6
0
This question is inspired by retrograde music. Retrograde music is a piece of music that can both be played normally (from the beginning to the end) as reversed (from the end the beginning). A similar thing exists in literature, this is called a semi-palindrome, e.g. "roma" and "amor". Your task is to write a retrograde program. If executed normally it has to encode a string with the morse code, decode it when executed reversed.
Task
You're to write a program or function that accepts a string and outputs it's morse code encoding (STDIN and STDOUT are used in case of a program, a function receives it's input as a function argument and returns a string). However, when you run the reverse of the program, it works the same except it decodes the input. Note that you don't have to use the same programming language. The reversing of the program is done manually.
Details
- Comments are not allowed in your program, as they would make this task very easy.
- You have to use the international morse code. This includes letters, numbers and some punctuation. See the link for a complete list. No prosigns or special characters have to be supported. There's one exception mentioned in the edit.
- You have to represent dots and dashes with
.
and-
. - Letters are separated with
(spaces), words are separated with
/
(slashes). - You can choose to use either use lower or uppercase. However, you have to be consistent (if your program only uses uppercase, the reversed program must do so too).
- You can assume the program will only receive valid input.
Example
Input of the normal program or output of the reversed program:
MORSE CODE?
Output of the normal program or input of the reversed program:
-- --- .-. ... . / -.-. --- -.. . ..--..
Score
Because I want to reward both clever (short) algorithms and creativity, Your score will be based upon your votes and the program length. Concretely, it will be 100 * amount of votes / program length (in bytes)
EDIT: The morse code site I mentioned uses the same code for opening and closing parentheses, however it's not my intention to let you implement a feature for recognizing this. So you have to use these more modern morse codes for the parentheses:
( = -.--.
) = -.--.-
A string followed by a semicolon is the standard CJam comment, so I think this falls foul of the prohibition "Comments are not allowed in your program, as they would make this task very easy." – Peter Taylor – 2015-01-09T11:09:25.783
@PeterTaylor its not a standard CJam comment. CJam does not have comments, so the only option to simulate comments is a string followed by a semi colon. Also, that is just the idea of the approach, I can achieve similar results by
0*
too – Optimizer – 2015-01-09T11:12:01.313Well, I'll let you make a counter-case rather than play devil's advocate myself.
– Peter Taylor – 2015-01-09T11:46:18.850@Deformyer from your edit :
So you can use these more modern morse codes for the parentheses
. It does not say that everyone has to put this new morse code for)
. Sounds more like an optional thing to me. – Optimizer – 2015-01-09T21:45:06.023@Deformyer I don't see a point in adding a compulsory rule so late. I have changed it for now, but any further rule changes will simply make me delete my answer. – Optimizer – 2015-01-09T21:55:20.247
@Optimizer I'm sorry but after encoding and decoding, () would become ((, this seemed wrong to me so I made an edit. – Def – 2015-01-09T22:01:27.350
Look ma, no eval! :) – Ilmari Karonen – 2015-01-11T22:23:42.330