Morse - Haskell

Iniciado por Sanko, Febrero 27, 2014, 06:31:27 PM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Febrero 27, 2014, 06:31:27 PM Ultima modificación: Mayo 01, 2014, 09:17:23 AM por Expermicid
Código: haskell
module Morse where
xAbc = zip (['a'..'z']++['0'..'9']++".,?-!:;()=$@_+~# '")([".- ", "-... ", "-.-. ", "-.. ", ". ","..-. ", "--. ", ".... ", ".. ", ".--- ", "-.- ", ".-.. ", "-- ", "-. ", "--- ", ".--. ", "--.- ", ".-. ", "... ", "- ", "..- ", "...- ",".-- ", "-..- ", "-.-- ", "--.. ", "----- ",".---- ", "..--- ", "...-- ", "....- ", "..... ", "-.... ", "--... ","---.. ", "----. ", ".-.-.- ", "--..-- ", "..--.. ", "-....- ", "-.-.-- ", "---... ", "-.-.-. ", "-.--. ", "-.--.- ", "-...- ", "...-..- ", ".--.-. ","..--.- ", ".-.-. ", ".-... ", "...-.- ", "/ ", ".----. "])
findPos list elt = [index | (index, e) <- zip [0..] list, e == elt]

xEnc xs = [snd (xAbc !! (x !! 0))| x <- [findPos ([fst (xAbc !! z) | z <- [0..length xAbc]]) x | x <- xs]]
xDec xs = [fst (xAbc !! (x !! 0))| x <- [findPos ([snd (xAbc !! z) | z <- [0..length xAbc]]) x | x <- xs]]


Output:
Código: php
*Morse> xEnc "hola"
[".... ","--- ",".-.. ",".- "]
*Morse> xDec [".... ","--- ",".-.. ",".- "]
"hola"
Sigueme en Twitter : @Sankosk
Estos nuevos staff no tienen puta idea XD