Skip to content

Instantly share code, notes, and snippets.

@jnape
Created January 30, 2013 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnape/4673922 to your computer and use it in GitHub Desktop.
Save jnape/4673922 to your computer and use it in GitHub Desktop.
Hack night run-length compression snippet
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