Created
January 30, 2013 15:16
-
-
Save jnape/4673922 to your computer and use it in GitHub Desktop.
Hack night run-length compression snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Snippet where | |
import Data.List | |
compress :: String -> String | |
compress = (foldl1 (++)) . (foldl (\acc xs -> acc ++ [(show.length) xs, (head xs):[]]) []) . group | |
compressions :: String -> [String] | |
compressions x = let n = compress x in n:compressions n | |
main :: IO () | |
main = let | |
nums = reverse $ map length $ take 22 $ compressions "1" | |
in | |
putStrLn $ (++ "\n" ++ (replicate (foldl1 (max) nums) '_')) $ foldl1 (++) $ intersperse "\n" $ map (\n -> "|" ++ (replicate (n-1) '.') ++ "x") $ nums |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment