AoC2019/day4.hs

30 lines
719 B
Haskell
Raw Normal View History

2019-12-05 08:44:18 +01:00
import Data.List as List
import Data.Char as Char
main = do
putStrLn("Hello")
issorted :: [Int] -> Bool
issorted xs = and $ zipWith(<=) xs (tail xs)
digits :: Int -> [Int]
digits = map Char.digitToInt . show
hasAdjacentPair :: [Int] -> Bool
hasAdjacentPair n = (maximum (map length (List.group n))) >= 2
hasAdjacentPairb :: [Int] -> Bool
hasAdjacentPairb n = elem 2 (map length (List.group n))
day4a :: Int -> Bool
day4a n =(hasAdjacentPair $ digits n) && ( issorted $ digits n )
day4b :: Int -> Bool
day4b n =(hasAdjacentPairb $ digits n) && ( issorted $ digits n )
filterDay4a :: [Int] -> [Int]
filterDay4a ns = filter(\n-> day4a n) ns
filterDay4b :: [Int] -> [Int]
filterDay4b ns = filter(\n-> day4b n) ns