Skip to content

Instantly share code, notes, and snippets.

@SpencerCDixon
Created November 17, 2014 21:58
Show Gist options
  • Save SpencerCDixon/df1dd172c57d7c32de20 to your computer and use it in GitHub Desktop.
Save SpencerCDixon/df1dd172c57d7c32de20 to your computer and use it in GitHub Desktop.
Morse Code - Comet Challenge
# Take in morse code and output correct english
require 'pry'
ALPHABET = {
".-"=> "A",
"-..."=> "B",
"-.-."=> "C",
"-.."=> "D",
"."=> "E",
"..-."=> "F",
"--."=> "G",
"...."=> "H",
".."=> "I",
".---"=> "J",
"-.-"=> "K",
".-.."=> "L",
"--"=> "M",
"-."=> "N",
"---"=> "O",
".--."=> "P",
"--.-"=> "Q",
".-."=> "R",
"..."=>"S",
"-"=>"T",
"..-"=>"U",
"...-"=>"V",
".--"=>"W",
"-..-"=>"X",
"-.--"=> "Y",
"--.."=> "Z",
"-.-.--" => "!",
".-.-" => ",",
".----." => "'",
}
def decode(code)
decoded_sentence = []
split_words = code.split('/')
split_words.each do |word|
letters = word.split(' ')
decoded_word = []
letters.each do |letter|
decoded_word << ALPHABET[letter]
end
decoded_sentence << decoded_word.join
end
binding.pry
decoded_sentence.join(' ')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment