Update day 2

This commit is contained in:
2024-12-02 16:41:59 +01:00
parent 6b7eac7281
commit 19bc483c50
2 changed files with 5 additions and 19 deletions

View File

@@ -1,3 +1,4 @@
isSortedGradually' :: (Integer -> Integer -> Bool) -> Bool -> [Integer] -> Bool
isSortedGradually' f mercy (x1:x2:xs) =
(diff >= 1 && diff <= 3 && f x1 x2 && isSortedGradually' f mercy (x2:xs))
@@ -8,14 +9,8 @@ isSortedGradually' f mercy _ = True
isSortedGradually f (x:xs) = isSortedGradually' f True (x:xs)
|| isSortedGradually' f False xs
isAscending :: [Integer] -> Bool
isAscending xs = isSortedGradually (<) xs
isDescending :: [Integer] -> Bool
isDescending xs = isSortedGradually (>) xs
isSafe :: [Integer] -> Bool
isSafe xs = isAscending xs || isDescending xs
isSafe xs = isSortedGradually (<) xs || isSortedGradually (>) xs
main :: IO()
main = interact $ show . sum . map (fromEnum . isSafe . map read . words) . lines