From: Neil Smith <NeilNjae@users.noreply.github.com>
Date: Mon, 2 Dec 2024 19:53:04 +0000 (+0000)
Subject: Added applicative version of isSafe
X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=0f3d17323d510b08228cf82f8d3786807fb1ca82;p=advent-of-code-24.git

Added applicative version of isSafe
---

diff --git a/advent02/Main.hs b/advent02/Main.hs
index 6f3af87..cb75ccb 100644
--- a/advent02/Main.hs
+++ b/advent02/Main.hs
@@ -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)
 
diff --git a/adventofcode24.cabal b/adventofcode24.cabal
index 565d1d9..7e4d98f 100644
--- a/adventofcode24.cabal
+++ b/adventofcode24.cabal
@@ -30,7 +30,7 @@ common common-extensions
                         , NegativeLiterals
                         , NumDecimals
                         -- , NoFieldSelectors
-                        , OverloadedLists
+                        -- , OverloadedLists
                         -- , OverloadedRecordDot
                         , OverloadedStrings
                         -- , PartialTypeSignatures