Code Golf: Morse code
Posted
by LiraNuna
on Stack Overflow
See other posts from Stack Overflow
or by LiraNuna
Published on 2009-08-29T22:54:30Z
Indexed on
2010/03/20
14:01 UTC
Read the original article
Hit count: 381
The challenge
The shortest code by character count, that will input a string using only alphabetical characters (upper and lower case), numbers, commas, periods and question mark, and returns a representation of the string in Morse code.
The Morse code output should consist of a dash (-
, ascii 0x2D) for a long beep (aka 'dah') and a dot (.
, ascii 0x2E) for short beep (aka 'dit').
Each letter should be separated by a space (' '
, ascii 0x20), and each word should be separated by a forward slash (/
, ascii 0x2F).
Morse code table:
Test cases:
Input:
Hello world
Output:
.... . .-.. .-.. --- / .-- --- .-. .-.. -..
Input:
Hello, Stackoverflow.
Output:
.... . .-.. .-.. --- --..-- / ... - .- -.-. -.- --- ...- . .-. ..-. .-.. --- .-- .-.-.-
Code count includes input/output (i.e full program).
© Stack Overflow or respective owner