aoc2021/Day8.hs

18 lines
567 B
Haskell
Raw Normal View History

2021-12-08 16:12:23 +00:00
module Day8 where
import System.IO (openFile, IOMode (ReadMode), hClose, hGetContents)
import Data.Text (splitOn, unpack, pack)
import Prelude hiding (splitAt)
splitAt :: String -> String -> [String]
splitAt delimiter str = map unpack $ splitOn (pack delimiter) $ pack str
main :: IO ()
main = do
input <- openFile "inputs/8.txt" ReadMode
contents <- hGetContents input
let patterns = map (splitAt " ") . splitAt " | " <$> lines contents
print . sum . map (length . filter (\x -> length x `elem` [2,3,4,7])) $ (!! 1) <$> patterns
hClose input