module Lib where import Data.List (delete) parsedFileString fileString = [[read word :: Int | word <- words line] | line <- lines fileString] getDiffs :: [Int] -> [Int] getDiffs report = [xiplus1 - xi | (xiplus1, xi) <- zip report (tail report)] checkReport :: [Int] -> Bool checkReport reports = (all (> 0) diffs || all (< 0) diffs) && all (\x -> let absX = abs x in absX > 0 && absX < 4) diffs where diffs = getDiffs reports -- This is a non-ideal brute-force approach but don't have time to improve checkReportDampened :: [Int] -> Bool checkReportDampened reports = checkReport reports || let reportSubsets = [checkReport (take n reports ++ drop (n + 1) reports) | n <- [0 .. (length reports)]] in or reportSubsets getSafeReportCount checkFun = foldr ((+) . fromEnum . checkFun) 0