Fix indentation

This commit is contained in:
Daniele Fucini
2025-12-05 09:04:23 +01:00
parent b6b02ac5a2
commit 7a68416c24
2 changed files with 17 additions and 17 deletions

View File

@@ -1,6 +1,6 @@
module Day02 module Day02
( day02_1, ( day02_1,
day02_2 day02_2,
) )
where where
@@ -9,25 +9,25 @@ import Data.List.Split (splitOn)
sumInvalid :: [Int] -> Int sumInvalid :: [Int] -> Int
sumInvalid = foldl addInvalid 0 sumInvalid = foldl addInvalid 0
where where
addInvalid acc n addInvalid acc n
| odd (length (show n)) = acc | odd (length (show n)) = acc
| let l2 = length (show n) `div` 2, take l2 (show n) == drop l2 (show n) = acc + n | let l2 = length (show n) `div` 2, take l2 (show n) == drop l2 (show n) = acc + n
| otherwise = acc | otherwise = acc
sumInvalid' :: [Int] -> Int sumInvalid' :: [Int] -> Int
sumInvalid' = foldl addInvalid 0 sumInvalid' = foldl addInvalid 0
where addInvalid acc n where
| let s = drop 1 $ show n ++ show n, show n `isInfixOf` take (length s - 1) s = acc + n addInvalid acc n
| otherwise = acc | let s = drop 1 $ show n ++ show n, show n `isInfixOf` take (length s - 1) s = acc + n
| otherwise = acc
getRange :: String -> [Int] getRange :: String -> [Int]
getRange r = [read (takeWhile (/= '-') r)..read $ drop 1 (dropWhile (/= '-') r)] getRange r = [read (takeWhile (/= '-') r) .. read $ drop 1 (dropWhile (/= '-') r)]
parseInput :: IO [Int] parseInput :: IO [Int]
parseInput = do parseInput = do
concatMap getRange . splitOn "," <$> readFile "input/day2.txt" concatMap getRange . splitOn "," <$> readFile "input/day2.txt"
day02_1 :: IO () day02_1 :: IO ()
day02_1 = do day02_1 = do
@@ -35,7 +35,7 @@ day02_1 = do
let result = sumInvalid values let result = sumInvalid values
putStrLn $ putStrLn $
"Day 2, Puzzle 1 solution: " "Day 2, Puzzle 1 solution: "
++ show result ++ show result
day02_2 :: IO () day02_2 :: IO ()
day02_2 = do day02_2 = do
@@ -43,4 +43,4 @@ day02_2 = do
let result = sumInvalid' values let result = sumInvalid' values
putStrLn $ putStrLn $
"Day 2, Puzzle 1 solution: " "Day 2, Puzzle 1 solution: "
++ show result ++ show result

View File

@@ -1,6 +1,6 @@
module Day03 module Day03
( day03_1, ( day03_1,
day03_2 day03_2,
) )
where where