shireen-bean / ruby-morse-code-challenge

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

General Assembly Logo

Morse Code Challenge

Convert Morse Code messages into text.

Adapted from these CodeWars exercises, created by user jolaf:

Prerequisites

  • None

Instructions

  1. Fork and clone this repository.
  2. Change into the new directory.
  3. Install dependencies.
  4. Create and checkout a new branch to work on.
  5. 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.

Requirements

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.

Bonus : parse_bits

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.

Source code distributed under the MIT license. Text and other assets copyright General Assembly, Inc., all rights reserved.

About

License:Other


Languages

Language:Ruby 100.0%