A little of the joy is gone now that I know the stdins and outs of anarchy golf, but the weird little exercises are still there.
-module(keypad).
-export([m/0]).
m()->
io:format(parse(tokenize([],[],io:get_line([])))).
tokenize(Ts,T,[H|Tail])->
case Tail of
[$1]->[[H|T]|Ts];
_->
case H of
$1->tokenize([T|Ts],[],Tail);
_->tokenize(Ts,[H|T],Tail)
end
end.
parse(Ts)->
lists:reverse(
lists:map(
fun([C|_]=T)->
case C of
$0->32;
_->key(C)+length(T)-1
end
end,Ts)).
key(I)->
case I of
$8->$t;
$9->$w;
_->97+3*(I-50)
end.
No comments:
Post a Comment