Browse Source

Day8

master
Arranun 2 years ago
parent
commit
bfa4f0a305
  1. 32
      day8.hs

32
day8.hs

@ -0,0 +1,32 @@
import Data.List as List
main = do
content <- getContents
let input = map (read . (:"")) content
let layers = getLayers input (6*25) []
let min = minimum (map (\x-> countOccurence x 0) layers)
let layer = head (filter(\x-> countOccurence x 0 == min) layers)
putStrLn (show $ (countOccurence layer 1) * (countOccurence layer 2))
let picture = foldl combineLayer (head layers) (tail layers)
mapM putStrLn (map show (getLayers picture 25 []))
getLayers :: [Int] -> Int -> [[Int]] -> [[Int]]
getLayers xs x ys= do
if (length xs) >= x
then do
let split = splitAt x xs
getLayers (snd split) x (ys ++ [fst split])
else ys
countOccurence :: [Int] -> Int -> Int
countOccurence xs x= length $ filter (x==) xs
compare :: Int -> Int -> Int
compare 0 y = 0
compare 1 y = 1
compare 2 y = y
combineLayer :: [Int] -> [Int] -> [Int]
combineLayer xs ys = zipWith Main.compare xs ys
Loading…
Cancel
Save