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

Posted by Nilesh S. (nilesh_s)
on 2013-01-14 14:04
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 by Markus Schirp (Guest)
on 2013-01-14 14:09
(Received via mailing list)
Homework?
Posted by Nilesh S. (nilesh_s)
on 2013-01-14 14:12
No.. its for company-question .. i have to understand this code asap.. 
also i am new to ruby..
Posted by Carlo E. Prelz (Guest)
on 2013-01-14 14:18
(Received via mailing list)
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
Posted by Nilesh S. (nilesh_s)
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..
Posted by Peter Hickman (Guest)
on 2013-01-14 14:21
(Received via mailing list)
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.
Posted by Nilesh S. (nilesh_s)
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..
Posted by Thiel Chang (thiel)
on 2013-01-14 14:32
(Received via mailing list)
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:
Posted by Peter Hickman (Guest)
on 2013-01-14 14:33
(Received via mailing list)
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.
Posted by Peter Hickman (Guest)
on 2013-01-14 14:38
(Received via mailing list)
So you also do not know how to use Google?

"convert morse code to text in C++"
Posted by "Hajdú Zoltán" <janicetr@fastmail.fm> (Guest)
on 2013-01-14 14:50
(Received via mailing list)
> 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
No account? Register here.