mass rename

Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
2024-12-20 22:34:32 +05:30
parent 2d87d98ffe
commit 4d1bd226ac
11 changed files with 20 additions and 20 deletions

36
src/Day02.hs Normal file
View File

@@ -0,0 +1,36 @@
module Main where
import qualified AoC as A (extract)
import Data.List (inits, tails)
import Text.Parsec (char, digit, many1, newline, parse, sepBy1, sepEndBy1)
import Text.Parsec.String (Parser)
parseReports :: Parser [[Int]]
parseReports =
sepEndBy1
(sepBy1 (read <$> many1 digit) (char ' '))
newline
safe :: [Int] -> Bool
safe xs =
let differences :: [Int]
differences = zipWith (-) (tail xs) xs
in all (\x -> (x >= 1) && (x <= 3)) differences || all (\x -> (x <= -1) && (x >= -3)) differences
part1 :: [[Int]] -> Int
part1 = length . filter safe
part2 :: [[Int]] -> Int
part2 = length . filter dampSafe
where
dampSafe :: [Int] -> Bool
dampSafe xs = any safe (zipWith (++) (inits xs) (tail (tails xs)))
main :: IO ()
main =
do
raw <- readFile "./inputs/day2.in"
-- parse the input
let reports = A.extract $ parse parseReports "" raw
putStr "Part 1: " >> print (part1 reports)
putStr "Part 2: " >> print (part2 reports)