Convert Morse Code messages into text.
Adapted from these CodeWars exercises, created by user jolaf:
- None
- Fork and clone this repository.
- Change into the new directory.
- Install dependencies.
- Create and checkout a new branch to work on.
- Fulfill the listed requirements.
Starter code is available in lib/challenge.rb
. A pull
request is not required, but it is necessary if you want a code review.
You may wish to refer to FAQs related to forking, cloning.
Create a method, decode_morse
, which takes a string of dots/dits ('.'
) and
dashes/dahs ('-'
) and converts it into a readable message.
A Morse Code dictionary, MORSE_CODE
, has been provided for you.
If an invalid letter code is passed in, decode_morse
should replace that
invalid letter with an asterisk ('*'
).
Letters are separated by space, while words are separated by a group of
three spaces.
Remove any leading or trailing whitespace.
You should be running rubocop
before diagnosing any bugs, since it finds
some of the most common sources of errors.
After rubocop
passes your code (ignore any warnings about spec_helper
),
you should run rspec
to run the included tests, which will tell you
whether or not you've met requirements.
Let's imagine that a signal is being sent along a wire; at the receiving end, it is being sampled and converted into a set of 1s and 0s. i.e. '1010100010001000' => "see"
The Morse Code specification dictates that:
- A 'dot' (
'.'
) is one time unit long - A 'dash' (
'-'
) is three time units long - The pause between each dot and dash in a letter is one time unit long.
- The pause between letters in a word is three time units long.
- The pause between words is 7 time units long
However, we don't necessarily know how fast the person on the other end is at sending their signals - the precise length of a 'time unit' is unknown. If they're a slow telegraphist, their dots and dashes might be stretched out, e.g.'111000111000111000000000111000000000111000000000' => "see"
The parse_bits
method should take a string of 1s and 0s and convert it into
the dots and dashes that were being sent.
Be sure to disregard any stretches of silence (i.e. 0s) before or after the
message.
- All content is licensed under a CCBYNCSA 4.0 license.
- All software code is licensed under GNU GPLv3. For commercial use or alternative licensing, please contact [email protected].