Ken Bloom wrote: > Ruby Quiz <james / grayproductions.net> wrote: >> 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). I don't even know Prolog, and I can see that your code is horribly broken. -- John W. Kennedy "Only an idiot fights a war on two fronts. Only the heir to the throne of the kingdom of idiots would fight a war on twelve fronts" -- J. Michael Straczynski. "Babylon 5", "Ceremonies of Light and Dark" * TagZilla 0.066 * http://tagzilla.mozdev.org