SHARE
TWEET

Untitled

a guest Dec 7th, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module Main where
  2.  
  3. import Data.List
  4. import Data.List.Split
  5. import Data.Ord
  6.  
  7. part1 layers = count '1' layer * count '2' layer
  8.   where layer = minimumBy (comparing (count '0')) layers
  9.         count digit = length . filter (==digit)
  10.  
  11. part2 (w, _) = unlines . chunksOf w . map render . foldl1 (zipWith combine)
  12.   where combine '2' p = p
  13.         combine p _ = p
  14.         render '0' = ' '
  15.         render '1' = 'X'
  16.         render '2' = ' '
  17.  
  18. main :: IO ()
  19. main = do
  20.   digits <- head . lines <$> getContents
  21.   let (w,h) = (25,6)
  22.       layers = chunksOf (w*h) digits
  23.   print $ part1 layers
  24.   putStrLn $ part2 (w, h) layers
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top