Fix indentation

This commit is contained in:
2024-12-08 16:28:47 +01:00
parent 0038d22c5b
commit c277c8d1fc
5 changed files with 40 additions and 40 deletions

View File

@ -13,8 +13,8 @@ countOccurrences word text = sum (map (countOccurrences' word) text) + sum (map
diags = diagonals text
countOccurrences' _ [] = 0
countOccurrences' word text@(_:rest) = if word `isPrefixOf` text
then 1 + countOccurrences' word rest
else countOccurrences' word rest
then 1 + countOccurrences' word rest
else countOccurrences' word rest
main = do
contents <- lines <$> readFile "day4.txt"

View File

@ -2,16 +2,16 @@ import Data.List (transpose, isPrefixOf, tails)
diagonals :: [String] -> [String]
diagonals xs = diagonals' xs ++ diagonals' ((transpose . reverse) xs)
where diagonals' xs = transpose (zipWith drop [0..] xs)
++ transpose (zipWith drop [1..] (transpose xs))
where diagonals' xs = transpose (zipWith drop [0..] xs)
++ transpose (zipWith drop [1..] (transpose xs))
countOccurrences :: String -> [String] -> Int
countOccurrences word text = sum (map (countOccurrences' word) diags) + sum (map (countOccurrences' word . reverse) diags)
where diags = diagonals text
countOccurrences' _ [] = 0
countOccurrences' word text@(_:rest) = if word `isPrefixOf` text
then 1 + countOccurrences' word rest
else countOccurrences' word rest
where diags = diagonals text
countOccurrences' _ [] = 0
countOccurrences' word text@(_:rest) = if word `isPrefixOf` text
then 1 + countOccurrences' word rest
else countOccurrences' word rest
submatricesVert :: Int -> [String] -> [[String]]
submatricesVert _ [] = []