Write Ascii85 to binary converter in 10 lines of code.
Hard Mode: Using Python.
Hardcore Mode: in Esoteric language of your choice.
Name:
Anonymous2009-05-25 9:48
Still doesn't work perfectly (outputs characters at the end which should be truncated). Does Haskell classify as an esoteric language?
import Data.Char (chr, ord, isSpace)
dec5, decode :: String -> String
dec5 xs = map (chr . fromInteger) $ reverse $ map (flip rem 256) $ take 4 $ iterate (flip div 256) n
where n = sum $ zipWith (*) (map (85^) $ reverse [0..4]) (map (\c -> toInteger $ ord c - 33) xs)
decode [] = []
decode s | head s == 'z' = (replicate 4 '\0') ++ (decode $ tail s)
| isSpace $ head s = decode $ tail s
| otherwise = (dec5 $ take 5 (s ++ cycle ['u'])) ++ (decode $ drop 5 s)