Telephone Keypad Letter Mapping Fixed by Chris Hagan

-module(keypad).\x0d
-export([m/0]).\x0d
m()->\x0d
\x09io:format(parse(tokenize([],[],io:get_line([])))).\x0d
tokenize(Ts,T,[H|Tail])->\x0d
\x09case Tail of\x0d
\x09\x09[$1]->[[H|T]|Ts];\x0d
\x09\x09_->\x0d
\x09\x09\x09case H of\x0d
\x09\x09\x09\x09$1->tokenize([T|Ts],[],Tail);\x0d
\x09\x09\x09\x09_->tokenize(Ts,[H|T],Tail)\x0d
\x09\x09\x09end\x0d
\x09end.\x0d
parse(Ts)->\x0d
\x09lists:reverse(\x0d
\x09\x09lists:map(\x0d
\x09\x09\x09fun([C|_]=T)->\x0d
\x09\x09\x09\x09case C of\x0d
\x09\x09\x09\x09\x09$0->32;\x0d
\x09\x09\x09\x09\x09_->key(C)+length(T)-1\x0d
\x09\x09\x09\x09end\x0d
\x09\x09\x09end,Ts)).\x0d
key(I)->\x0d
\x09case I of\x0d
\x09\x09$8->$t;\x0d
\x09\x09$9->$w;\x0d
\x09\x09_->97+3*(I-50)\x0d
\x09end.\x0d

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page