day4
This commit is contained in:
parent
7b8e8914c4
commit
f0e8c8488d
|
@ -0,0 +1,29 @@
|
|||
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
|
Loading…
Reference in New Issue
Block a user