Added applicative version of isSafe
authorNeil Smith <NeilNjae@users.noreply.github.com>
Mon, 2 Dec 2024 19:53:04 +0000 (19:53 +0000)
committerNeil Smith <NeilNjae@users.noreply.github.com>
Mon, 2 Dec 2024 19:53:04 +0000 (19:53 +0000)
advent02/Main.hs
adventofcode24.cabal

index 6f3af879a9de44268f95d04d3bf4994e873e70fe..cb75ccb1300567ebe57196d7bd777e8cfedacd3a 100644 (file)
@@ -30,6 +30,10 @@ smallEnough = all ((<= 3) . abs)
 
 safeWhenDamped = (any isSafe) . damped
 
+isSafeA :: [Int] -> Bool
+isSafeA xs = and $ [allSameSign, bigEnough, smallEnough] <*> (pure diffs)
+  where diffs = zipWith (-) xs (tail xs)
+
 damped :: [Int] -> [[Int]]
 damped line = zipWith (++) (inits line) (drop 1 $ tails line)
 
index 565d1d98839ca839dca8ec3113bd7911383ddecd..7e4d98fd8fe5f9e75bacaf149ada7040d38e0362 100644 (file)
@@ -30,7 +30,7 @@ common common-extensions
                         , NegativeLiterals
                         , NumDecimals
                         -- , NoFieldSelectors
-                        , OverloadedLists
+                        -- , OverloadedLists
                         -- , OverloadedRecordDot
                         , OverloadedStrings
                         -- , PartialTypeSignatures