Re: Morse
- Posted by ghaberek (admin) Sep 06, 2014
- 1666 views
AFAIK (I learnt Morse in the military) Its not case sensitive, so why not use lower() and shorten the lookup table?
You're right, it's not case-sensitive. I am sacrificing the extra few bytes of memory for the sake of speed. Passing everything through lower() takes time. Indexing everything directly is faster. If we simply "copy" the values from A-Z to a-z, it should use less memory (due to Euphoria's copy-on-write sequence management). Although if we add it all up, we're probably only saving about 400 bytes of memory.
MORSE['a'] = MORSE['A'] MORSE['b'] = MORSE['B'] MORSE['c'] = MORSE['C'] MORSE['d'] = MORSE['D'] MORSE['e'] = MORSE['E'] MORSE['f'] = MORSE['F'] MORSE['g'] = MORSE['G'] MORSE['h'] = MORSE['H'] MORSE['i'] = MORSE['I'] MORSE['j'] = MORSE['J'] MORSE['k'] = MORSE['K'] MORSE['l'] = MORSE['L'] MORSE['m'] = MORSE['M'] MORSE['n'] = MORSE['N'] MORSE['o'] = MORSE['O'] MORSE['p'] = MORSE['P'] MORSE['q'] = MORSE['Q'] MORSE['r'] = MORSE['R'] MORSE['s'] = MORSE['S'] MORSE['t'] = MORSE['T'] MORSE['u'] = MORSE['U'] MORSE['v'] = MORSE['V'] MORSE['w'] = MORSE['W'] MORSE['x'] = MORSE['X'] MORSE['y'] = MORSE['Y'] MORSE['z'] = MORSE['Z']
BTW, we never used @ and a few others you have, but its nice to know that they are there.
Brings back 35 year old memories :)
Wikipedia has a pretty comprehensive list of Letters, numbers, punctuation, prosigns and non-English variants for Morse code, which is what I used as a reference.
-Greg