J
James Edward Gray II
This is my first rubyquiz as well.
Just wanted to say a quick welcome to all the new faces. Glad you
decided to join us.
James Edward Gray II
This is my first rubyquiz as well.
I'd welcome any suggestion for making it more ruby-like.
'Z'}'T','..-'=>'U','...-'=>'V','.--'=>'W','-..-'=>'X','-.--'=>'Y','--..'=>
Ken said:Ruby Quiz said:The three rules of Ruby Quiz:
1. Please do not post any solutions or spoiler discussion for this quiz until
48 hours have passed from the time on this message.
2. Support Ruby Quiz by submitting ideas as often as you can:
http://www.rubyquiz.com/
3. Enjoy!
Technically, I'm not breaking any rules in suggesting that the most
natural language for this problem is Prolog:
m('.-', a). m('-...', b). m('-.-.', c).
m('-..', d). m('.', e). m('..-.', f).
m('--.', g). m('....', h). m('..', i).
m('.---', j). m('-.-', k). m('.-..', l).
m('--', m). m('-.', n). m('---', o).
m('.--.', p). m('--.-', q). m('.-.', r).
m('...', s). m('-', t). m('..-', u).
m('...-', v). m('.--', w). m('-..-', x).
m('-.--', y). m('--..', z).
morse_decode(Text,Translation):-atom_chars(Text,List),
morse_i(List,TranslationList),
atom_chars(Translation,TranslationList).
morse_encode(Text,Translation):-
atom_chars(Translation,TranslationList),
morse_i(List,TranslationList),
atom_chars(Text,List).
morse_i([],[]).
morse_i(List,Translation):-m(First,Letter),atom_chars(First,FirstList),
append(FirstList,RestList,List),Translation=[Letter|RestTrans],
morse_i(RestList,RestTrans).
Examples of use:
morse_decode('...---...',X).
morse_decode('...---...',sos).
morse_encode(X,'sos').
morse_encode('...---...',sos).
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.