Problem A Keitai Message

http://www.deqnotes.net/acmicpc/p0003/ja の問題。これは結構きれいに書けたと思われる。

import Data.List ( group )

button 1 = cycle ['.', ',', '!', '?', ' ']
button 2 = cycle ['a', 'b', 'c']
button 3 = cycle ['d' ,'e' ,'f']
button 4 = cycle ['g' ,'h' ,'i']
button 5 = cycle ['j' ,'k' ,'l']
button 6 = cycle ['m' ,'n' ,'o']
button 7 = cycle ['p' ,'q' ,'r' ,'s']
button 8 = cycle ['t' ,'u' ,'v']
button 9 = cycle ['w' ,'x' ,'y' ,'z']

decode str =
    let nonzero = filter ((/='0').head) $ group str
        tupple  = map (\l -> (read [head l], length l)) nonzero
    in  map (\(n,m) -> (button n)!!(m-1)) tupple
Main> decode "44033055505550666011011111090666077705550301110"
"hello, world!"
Main>