Fix indentation
This commit is contained in:
28
src/Day02.hs
28
src/Day02.hs
@@ -1,6 +1,6 @@
|
||||
module Day02
|
||||
( day02_1,
|
||||
day02_2
|
||||
day02_2,
|
||||
)
|
||||
where
|
||||
|
||||
@@ -9,25 +9,25 @@ import Data.List.Split (splitOn)
|
||||
|
||||
sumInvalid :: [Int] -> Int
|
||||
sumInvalid = foldl addInvalid 0
|
||||
where
|
||||
addInvalid acc n
|
||||
| odd (length (show n)) = acc
|
||||
| let l2 = length (show n) `div` 2, take l2 (show n) == drop l2 (show n) = acc + n
|
||||
| otherwise = acc
|
||||
where
|
||||
addInvalid acc n
|
||||
| odd (length (show n)) = acc
|
||||
| let l2 = length (show n) `div` 2, take l2 (show n) == drop l2 (show n) = acc + n
|
||||
| otherwise = acc
|
||||
|
||||
sumInvalid' :: [Int] -> Int
|
||||
sumInvalid' = foldl addInvalid 0
|
||||
where addInvalid acc n
|
||||
| let s = drop 1 $ show n ++ show n, show n `isInfixOf` take (length s - 1) s = acc + n
|
||||
| otherwise = acc
|
||||
|
||||
where
|
||||
addInvalid acc n
|
||||
| let s = drop 1 $ show n ++ show n, show n `isInfixOf` take (length s - 1) s = acc + n
|
||||
| otherwise = acc
|
||||
|
||||
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 = do
|
||||
concatMap getRange . splitOn "," <$> readFile "input/day2.txt"
|
||||
concatMap getRange . splitOn "," <$> readFile "input/day2.txt"
|
||||
|
||||
day02_1 :: IO ()
|
||||
day02_1 = do
|
||||
@@ -35,7 +35,7 @@ day02_1 = do
|
||||
let result = sumInvalid values
|
||||
putStrLn $
|
||||
"Day 2, Puzzle 1 solution: "
|
||||
++ show result
|
||||
++ show result
|
||||
|
||||
day02_2 :: IO ()
|
||||
day02_2 = do
|
||||
@@ -43,4 +43,4 @@ day02_2 = do
|
||||
let result = sumInvalid' values
|
||||
putStrLn $
|
||||
"Day 2, Puzzle 1 solution: "
|
||||
++ show result
|
||||
++ show result
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module Day03
|
||||
( day03_1,
|
||||
day03_2
|
||||
day03_2,
|
||||
)
|
||||
where
|
||||
|
||||
|
||||
Reference in New Issue
Block a user