Skip to content

Instantly share code, notes, and snippets.

@Ailrun
Created July 30, 2021 17:04
Show Gist options
  • Save Ailrun/f418056aa812581d4f0bd681d251344f to your computer and use it in GitHub Desktop.
Save Ailrun/f418056aa812581d4f0bd681d251344f to your computer and use it in GitHub Desktop.
import Data.Bits
import Data.Bool
digitData :: [Int]
digitData = [63198, 18724, 59342, 62414, 37850, 62366, 63378, 37454, 63454, 37854]
chunk :: Int -> [a] -> [[a]]
chunk _ [] = []
chunk n as = take n as : chunk n (drop n as)
displayDigit :: Int -> [String]
displayDigit = chunk 3 . (`fmap` [1..15]) . (bool ' ' '#' .) . testBit . (digitData !!)
padding :: Int -> [String]
padding n = replicate 5 $ replicate n ' '
display :: Int -> String
display = unlines . go
where
go n
| q > 0 = zipWith3 (\x y z -> x ++ y ++ z) (go q) (padding 2) (displayDigit r)
| otherwise = displayDigit r
where
(q, r) = n `quotRem` 10
main :: IO ()
main = getLine >>= putStrLn . display . read
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment