Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,25 @@
|
|||
import Data.List (delete, elemIndex, mapAccumL)
|
||||
|
||||
import Data.Maybe (fromJust)
|
||||
|
||||
table :: String
|
||||
table = ['a' .. 'z']
|
||||
|
||||
encode :: String -> [Int]
|
||||
encode =
|
||||
let f t s = (s : delete s t, fromJust (elemIndex s t))
|
||||
in snd . mapAccumL f table
|
||||
|
||||
decode :: [Int] -> String
|
||||
decode = snd . mapAccumL f table
|
||||
where
|
||||
f t i =
|
||||
let s = (t !! i)
|
||||
in (s : delete s t, s)
|
||||
|
||||
main :: IO ()
|
||||
main =
|
||||
mapM_ print $
|
||||
(,) <*> uncurry ((==) . fst) <$> -- Test that ((fst . fst) x) == snd x)
|
||||
((,) <*> (decode . snd) <$>
|
||||
((,) <*> encode <$> ["broood", "bananaaa", "hiphophiphop"]))
|
||||
Loading…
Add table
Add a link
Reference in a new issue