Conversion of Ruby-code to c/c++ code :: URGENT Plz help

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 }

--
Posted via http://www.ruby-forum.com/.

Homework?

···

On Mon, Jan 14, 2013 at 10:04:22PM +0900, Nilesh S. wrote:

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 }

--
Posted via http://www.ruby-forum.com/\.

No.. its for company-question .. i have to understand this code asap..
also i am new to ruby..

···

--
Posted via http://www.ruby-forum.com/.

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:

···

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 }

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

···

Subject: Re: Conversion of Ruby-code to c/c++ code :: URGENT Plz help
  Date: Mon 14 Jan 13 10:12:18PM +0900

--
  * Se la Strada e la sua Virtu' non fossero state messe da parte,
* K * Carlo E. Prelz - fluido@fluido.as che bisogno ci sarebbe
  * di parlare tanto di amore e di rettitudine? (Chuang-Tzu)

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 14 January 2013 13:12, Nilesh S. <lists@ruby-forum.com> wrote:

No.. its for company-question .. i have to understand this code asap..
also i am new to ruby..

--
Posted via http://www.ruby-forum.com/\.

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..

···

--
Posted via http://www.ruby-forum.com/\.

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..

···

--
Posted via http://www.ruby-forum.com/\.

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.

So you also do not know how to use Google?

"convert morse code to text in C++"

i know C++ but don't know the algorithm of morse-code
conversion........

Best regards:

Z.