Browse Source

day4

day7backup
Arranun 2 years ago
parent
commit
f0e8c8488d
  1. 29
      day4.hs

29
day4.hs

@ -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…
Cancel
Save