Another, for fun: Morse
you should add "mind-reading" on your set of skills Lee, as that would have been my next challenge. <decrypting morse code>
Good times LM
Though, unfortunately general alphabetical Morse code isn't as interesting, since it doesn't follow a pattern like the Morse code for the integers...
Here are two very quickly written conversion functions:
(defun words->morse ( s )
(substr
(apply 'strcat
(mapcar
(function
(lambda ( a )
(if (setq a (cadr (assoc a morsetable)))
(strcat " " a)
""
)
)
)
(vl-string->list (strcase s))
)
)
2
)
)
(defun morse->words ( s / f )
(defun f ( s l / c p )
(cond
( (wcmatch s " *")
(cons 32 (f (substr s 4) l))
)
( (setq p (vl-string-position 32 s))
(if (setq c (cadr (assoc (substr s 1 p) l)))
(cons c (f (substr s (+ 2 p)) l))
(f (substr s (+ 2 p)) l)
)
)
( (setq c (cadr (assoc s l)))
(list c)
)
( "" )
)
)
(vl-list->string (f s (mapcar 'reverse morsetable)))
)
(setq morsetable
'(
(32 " ")
(65 "·-")
(66 "-···")
(67 "-·-·")
(68 "-··")
(69 "·")
(70 "··-·")
(71 "--·")
(72 "····")
(73 "··")
(74 "·---")
(75 "-·-")
(76 "·-··")
(77 "--")
(78 "-·")
(79 "---")
(80 "·--·")
(81 "--·-")
(82 "·-·")
(83 "···")
(84 "-")
(85 "··-")
(86 "···-")
(87 "·--")
(88 "-··-")
(89 "-·--")
(90 "--··")
)
)
_$ (words->morse "THE SWAMP")
"- ···· · ··· ·-- ·- -- ·--·"
_$ (morse->words (words->morse "THE SWAMP"))
"THE SWAMP"