From 0f3d17323d510b08228cf82f8d3786807fb1ca82 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Mon, 2 Dec 2024 19:53:04 +0000 Subject: [PATCH] Added applicative version of isSafe --- advent02/Main.hs | 4 ++++ adventofcode24.cabal | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) 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 -- 2.34.1