Hi.. I urgent require to convert the following ruby-code to c/c++ code.
If some-one have both the knowledge ..plz help me.. At least give me
some algorithm to it.. IT's ABOUT THE MORSE-CODE CONVERSION TO STRINGS
IN ALPHABETICAL ORDER
----------------------------------------------------------------------
#!/usr/bin/env ruby -wKU
require "set"
MORSE_LETTERS = %w[.- -... -.-. -.. . ..-. --. .... .. .--- -.- .-..
--
-. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --..]
ENCODINGS = Hash[*MORSE_LETTERS.zip(('A'..'Z').to_a).flatten]
def morse_decodings(word)
# iterate through matching prefixes
ENCODINGS.select { |p,l| p == word[0,p.size] }.map do |
prefix,letter|
# gather decoded suffixes for the current prefix
suffixes = morse_decodings( word[prefix.size,word.size] )
# append decoded suffixes to decoded letter
suffixes.empty? ? letter : suffixes.map { |s| letter + s }
end.flatten
end
decodings = morse_decodings(readline.chomp).sort
puts "All Possible Decodings:"
decodings.each { |e| puts e }
on 2013-01-14 14:04
on 2013-01-14 14:12
No.. its for company-question .. i have to understand this code asap.. also i am new to ruby..
on 2013-01-14 14:18
Subject: Re: Conversion of Ruby-code to c/c++ code :: URGENT Plz help
Date: Mon 14 Jan 13 10:12:18PM +0900
Quoting Nilesh S. (lists@ruby-forum.com):
> No.. its for company-question .
Funny. A company dabbling with Morse code in the 21st century...
I may want to send them a CV...!
Carlo
on 2013-01-14 14:20
Carlo E. Prelz wrote in post #1092231: > Subject: Re: Conversion of Ruby-code to c/c++ code :: URGENT Plz help > Date: Mon 14 Jan 13 10:12:18PM +0900 > > Quoting Nilesh S. (lists@ruby-forum.com): > >> No.. its for company-question . > > Funny. A company dabbling with Morse code in the 21st century... > I may want to send them a CV...! > > Carlo I just want to know the algorithm for the code... rest i'll do it..
on 2013-01-14 14:21
If you know neither Ruby or C++ then no one can help you. The job you are trying to get will have much harder problems than this interview question.
on 2013-01-14 14:26
Peter Hickman wrote in post #1092234: > If you know neither Ruby or C++ then no one can help you. The job you > are > trying to get will have much harder problems than this interview > question. i know C++ but don't know the algorithm of morse-code conversion........ finally i found the program in RUBY language.. but i don't understand it... explaining this code steps-by-steps will be grateful ...... plz help..
on 2013-01-14 14:32
Hi, Is this a joke? My advice: read a Ruby book to get familiar with the Ruby language. Thiel Op 14-1-2013 14:04, Nilesh S. schreef:
on 2013-01-14 14:33
It takes a stream of . and - and sees what it might be: $ ruby morse.rb ..-..-..-.. All Possible Decodings: EAEAEAEE EAEAEAI EAEAEED ... Of course you could run the program and find out for yourself.
on 2013-01-14 14:50
> i know C++ but don't know the algorithm of morse-code > conversion........ http://en.wikipedia.org/wiki/Morse_code Best regards: Z.
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.