Rename days 1-9 with heading zero
This commit is contained in:
		@@ -33,24 +33,24 @@ executable adventofcode2024
 | 
				
			|||||||
                       -Wpartial-fields
 | 
					                       -Wpartial-fields
 | 
				
			||||||
                       -Wredundant-constraints
 | 
					                       -Wredundant-constraints
 | 
				
			||||||
  other-modules:
 | 
					  other-modules:
 | 
				
			||||||
    Day1.Puzzle1
 | 
					    Day01.Puzzle1
 | 
				
			||||||
    Day1.Puzzle2
 | 
					    Day01.Puzzle2
 | 
				
			||||||
    Day2.Puzzle1
 | 
					    Day02.Puzzle1
 | 
				
			||||||
    Day2.Puzzle2
 | 
					    Day02.Puzzle2
 | 
				
			||||||
    Day3.Puzzle1
 | 
					    Day03.Puzzle1
 | 
				
			||||||
    Day3.Puzzle2
 | 
					    Day03.Puzzle2
 | 
				
			||||||
    Day4.Puzzle1
 | 
					    Day04.Puzzle1
 | 
				
			||||||
    Day4.Puzzle2
 | 
					    Day04.Puzzle2
 | 
				
			||||||
    Day5.Puzzle1
 | 
					    Day05.Puzzle1
 | 
				
			||||||
    Day5.Puzzle2
 | 
					    Day05.Puzzle2
 | 
				
			||||||
    Day6.Puzzle1
 | 
					    Day06.Puzzle1
 | 
				
			||||||
    Day6.Puzzle2
 | 
					    Day06.Puzzle2
 | 
				
			||||||
    Day7.Puzzle1
 | 
					    Day07.Puzzle1
 | 
				
			||||||
    Day7.Puzzle2
 | 
					    Day07.Puzzle2
 | 
				
			||||||
    Day8.Puzzle1
 | 
					    Day08.Puzzle1
 | 
				
			||||||
    Day8.Puzzle2
 | 
					    Day08.Puzzle2
 | 
				
			||||||
    Day9.Puzzle1
 | 
					    Day09.Puzzle1
 | 
				
			||||||
    Day9.Puzzle2
 | 
					    Day09.Puzzle2
 | 
				
			||||||
    Day10.Puzzle1
 | 
					    Day10.Puzzle1
 | 
				
			||||||
    Day11.Puzzle1
 | 
					    Day11.Puzzle1
 | 
				
			||||||
    Day11.Puzzle2
 | 
					    Day11.Puzzle2
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,14 +1,14 @@
 | 
				
			|||||||
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
 | 
					{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module Day1.Puzzle1 (day1_1) where
 | 
					module Day01.Puzzle1 (day01_1) where
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import Data.List (sort, transpose)
 | 
					import Data.List (sort, transpose)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
listDistance :: [Int] -> [Int] -> Int
 | 
					listDistance :: [Int] -> [Int] -> Int
 | 
				
			||||||
listDistance xs ys = sum $ map abs $ zipWith (-) (sort xs) (sort ys)
 | 
					listDistance xs ys = sum $ map abs $ zipWith (-) (sort xs) (sort ys)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
day1_1 :: IO ()
 | 
					day01_1 :: IO ()
 | 
				
			||||||
day1_1 = do
 | 
					day01_1 = do
 | 
				
			||||||
  contents <- lines <$> readFile "input/day1.txt"
 | 
					  contents <- lines <$> readFile "input/day1.txt"
 | 
				
			||||||
  let [x, y] = transpose $ map read . words <$> contents
 | 
					  let [x, y] = transpose $ map read . words <$> contents
 | 
				
			||||||
  putStrLn $
 | 
					  putStrLn $
 | 
				
			||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
 | 
					{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module Day1.Puzzle2 (day1_2) where
 | 
					module Day01.Puzzle2 (day01_2) where
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import Data.List (group, sort, transpose, uncons)
 | 
					import Data.List (group, sort, transpose, uncons)
 | 
				
			||||||
import Data.Maybe (fromJust)
 | 
					import Data.Maybe (fromJust)
 | 
				
			||||||
@@ -10,8 +10,8 @@ similarityScore xs ys =
 | 
				
			|||||||
  let elemsY = [(fst . fromJust $ uncons y, length y) | y <- (group . sort) ys]
 | 
					  let elemsY = [(fst . fromJust $ uncons y, length y) | y <- (group . sort) ys]
 | 
				
			||||||
   in sum [x * snd y | x <- xs, y <- elemsY, x == fst y]
 | 
					   in sum [x * snd y | x <- xs, y <- elemsY, x == fst y]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
day1_2 :: IO ()
 | 
					day01_2 :: IO ()
 | 
				
			||||||
day1_2 = do
 | 
					day01_2 = do
 | 
				
			||||||
  contents <- lines <$> readFile "input/day1.txt"
 | 
					  contents <- lines <$> readFile "input/day1.txt"
 | 
				
			||||||
  let [x, y] = transpose $ map read . words <$> contents
 | 
					  let [x, y] = transpose $ map read . words <$> contents
 | 
				
			||||||
  putStrLn $
 | 
					  putStrLn $
 | 
				
			||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
module Day2.Puzzle1 (day2_1) where
 | 
					module Day02.Puzzle1 (day02_1) where
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import Data.List (sort, sortBy)
 | 
					import Data.List (sort, sortBy)
 | 
				
			||||||
import Data.Ord
 | 
					import Data.Ord
 | 
				
			||||||
@@ -10,8 +10,8 @@ isSafe xs = (isAscending xs || isDescending xs) && maximum distances <= 3 && min
 | 
				
			|||||||
    isDescending x = x == sortBy (comparing Down) x
 | 
					    isDescending x = x == sortBy (comparing Down) x
 | 
				
			||||||
    distances = map abs $ zipWith (-) xs (drop 1 xs)
 | 
					    distances = map abs $ zipWith (-) xs (drop 1 xs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
day2_1 :: IO ()
 | 
					day02_1 :: IO ()
 | 
				
			||||||
day2_1 = do
 | 
					day02_1 = do
 | 
				
			||||||
  contents <- lines <$> readFile "input/day2.txt"
 | 
					  contents <- lines <$> readFile "input/day2.txt"
 | 
				
			||||||
  let reports = map read . words <$> contents
 | 
					  let reports = map read . words <$> contents
 | 
				
			||||||
  putStrLn $
 | 
					  putStrLn $
 | 
				
			||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
module Day2.Puzzle2 (day2_2) where
 | 
					module Day02.Puzzle2 (day02_2) where
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import Data.List (inits, sort, sortBy, tails)
 | 
					import Data.List (inits, sort, sortBy, tails)
 | 
				
			||||||
import Data.Ord
 | 
					import Data.Ord
 | 
				
			||||||
@@ -16,8 +16,8 @@ removeLevel xs = zipWith (++) ys zs
 | 
				
			|||||||
    ys = map init $ drop 1 (inits xs)
 | 
					    ys = map init $ drop 1 (inits xs)
 | 
				
			||||||
    zs = map (drop 1) $ init (tails xs)
 | 
					    zs = map (drop 1) $ init (tails xs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
day2_2 :: IO ()
 | 
					day02_2 :: IO ()
 | 
				
			||||||
day2_2 = do
 | 
					day02_2 = do
 | 
				
			||||||
  contents <- lines <$> readFile "input/day2.txt"
 | 
					  contents <- lines <$> readFile "input/day2.txt"
 | 
				
			||||||
  let reports = map read . words <$> contents
 | 
					  let reports = map read . words <$> contents
 | 
				
			||||||
  putStrLn $
 | 
					  putStrLn $
 | 
				
			||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
module Day3.Puzzle1 (day3_1) where
 | 
					module Day03.Puzzle1 (day03_1) where
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import Data.List.Split (splitOn)
 | 
					import Data.List.Split (splitOn)
 | 
				
			||||||
import Text.Regex.TDFA (getAllTextMatches, (=~))
 | 
					import Text.Regex.TDFA (getAllTextMatches, (=~))
 | 
				
			||||||
@@ -8,8 +8,8 @@ sumMul xs =
 | 
				
			|||||||
  let vals = map (splitOn "," . filter (`elem` "0123456789,")) xs
 | 
					  let vals = map (splitOn "," . filter (`elem` "0123456789,")) xs
 | 
				
			||||||
   in sum $ map (product . map read) vals
 | 
					   in sum $ map (product . map read) vals
 | 
				
			||||||
 | 
					
 | 
				
			||||||
day3_1 :: IO ()
 | 
					day03_1 :: IO ()
 | 
				
			||||||
day3_1 = do
 | 
					day03_1 = do
 | 
				
			||||||
  contents <- readFile "input/day3.txt"
 | 
					  contents <- readFile "input/day3.txt"
 | 
				
			||||||
  let mults = getAllTextMatches (contents =~ "mul\\([0-9]+,[0-9]+\\)") :: [String]
 | 
					  let mults = getAllTextMatches (contents =~ "mul\\([0-9]+,[0-9]+\\)") :: [String]
 | 
				
			||||||
  putStrLn $
 | 
					  putStrLn $
 | 
				
			||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
module Day3.Puzzle2 (day3_2) where
 | 
					module Day03.Puzzle2 (day03_2) where
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import Data.List (isPrefixOf)
 | 
					import Data.List (isPrefixOf)
 | 
				
			||||||
import Data.List.Split (split, splitOn, startsWith)
 | 
					import Data.List.Split (split, splitOn, startsWith)
 | 
				
			||||||
@@ -12,8 +12,8 @@ sumMul xs =
 | 
				
			|||||||
filterDonts :: [String] -> String
 | 
					filterDonts :: [String] -> String
 | 
				
			||||||
filterDonts = concat . concatMap (filter (not . isPrefixOf "don't()") . split (startsWith "do()"))
 | 
					filterDonts = concat . concatMap (filter (not . isPrefixOf "don't()") . split (startsWith "do()"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
day3_2 :: IO ()
 | 
					day03_2 :: IO ()
 | 
				
			||||||
day3_2 = do
 | 
					day03_2 = do
 | 
				
			||||||
  contents <- split (startsWith "don't()") <$> readFile "input/day3.txt"
 | 
					  contents <- split (startsWith "don't()") <$> readFile "input/day3.txt"
 | 
				
			||||||
  let mults = getAllTextMatches (filterDonts contents =~ "mul\\([0-9]+,[0-9]+\\)") :: [String]
 | 
					  let mults = getAllTextMatches (filterDonts contents =~ "mul\\([0-9]+,[0-9]+\\)") :: [String]
 | 
				
			||||||
  putStrLn $
 | 
					  putStrLn $
 | 
				
			||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
module Day4.Puzzle1 (day4_1) where
 | 
					module Day04.Puzzle1 (day04_1) where
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import Data.List (isPrefixOf, transpose)
 | 
					import Data.List (isPrefixOf, transpose)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -26,8 +26,8 @@ countOccurrences word text =
 | 
				
			|||||||
        then 1 + countOccurrences' word rest
 | 
					        then 1 + countOccurrences' word rest
 | 
				
			||||||
        else countOccurrences' w rest
 | 
					        else countOccurrences' w rest
 | 
				
			||||||
 | 
					
 | 
				
			||||||
day4_1 :: IO ()
 | 
					day04_1 :: IO ()
 | 
				
			||||||
day4_1 = do
 | 
					day04_1 = do
 | 
				
			||||||
  contents <- lines <$> readFile "input/day4.txt"
 | 
					  contents <- lines <$> readFile "input/day4.txt"
 | 
				
			||||||
  putStrLn $
 | 
					  putStrLn $
 | 
				
			||||||
    "Day 4, Puzzle 1 solution: "
 | 
					    "Day 4, Puzzle 1 solution: "
 | 
				
			||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
module Day4.Puzzle2 (day4_2) where
 | 
					module Day04.Puzzle2 (day04_2) where
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import Data.List (isPrefixOf, tails, transpose)
 | 
					import Data.List (isPrefixOf, tails, transpose)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -27,8 +27,8 @@ submatricesVert n matrix@(_ : xxs) = submatrix matrix ++ submatricesVert n xxs
 | 
				
			|||||||
  where
 | 
					  where
 | 
				
			||||||
    submatrix m = [take n $ map (take n) m]
 | 
					    submatrix m = [take n $ map (take n) m]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
day4_2 :: IO ()
 | 
					day04_2 :: IO ()
 | 
				
			||||||
day4_2 = do
 | 
					day04_2 = do
 | 
				
			||||||
  contents <- lines <$> readFile "input/day4.txt"
 | 
					  contents <- lines <$> readFile "input/day4.txt"
 | 
				
			||||||
  let xmas = length . concatMap (filter (\x -> countOccurrences "MAS" x == 2) . submatricesVert 3) . transpose $ map tails contents
 | 
					  let xmas = length . concatMap (filter (\x -> countOccurrences "MAS" x == 2) . submatricesVert 3) . transpose $ map tails contents
 | 
				
			||||||
  putStrLn $ "Day 4, Puzzle 2 solution: " ++ show xmas
 | 
					  putStrLn $ "Day 4, Puzzle 2 solution: " ++ show xmas
 | 
				
			||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
{-# OPTIONS_GHC -Wno-incomplete-patterns #-}
 | 
					{-# OPTIONS_GHC -Wno-incomplete-patterns #-}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module Day5.Puzzle1 (day5_1) where
 | 
					module Day05.Puzzle1 (day05_1) where
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import Data.List.Split (splitOn)
 | 
					import Data.List.Split (splitOn)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -13,8 +13,8 @@ isSorted rules (x : xs) =
 | 
				
			|||||||
getMiddle :: [String] -> String
 | 
					getMiddle :: [String] -> String
 | 
				
			||||||
getMiddle xs = xs !! (length xs `div` 2)
 | 
					getMiddle xs = xs !! (length xs `div` 2)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
day5_1 :: IO ()
 | 
					day05_1 :: IO ()
 | 
				
			||||||
day5_1 = do
 | 
					day05_1 = do
 | 
				
			||||||
  contents <- map (splitOn "|") . lines <$> readFile "input/day5.txt"
 | 
					  contents <- map (splitOn "|") . lines <$> readFile "input/day5.txt"
 | 
				
			||||||
  let rules = [(x, y) | [x, y] <- takeWhile (/= [""]) contents]
 | 
					  let rules = [(x, y) | [x, y] <- takeWhile (/= [""]) contents]
 | 
				
			||||||
      updates = concatMap (map (splitOn ",")) . drop 1 $ dropWhile (/= [""]) contents
 | 
					      updates = concatMap (map (splitOn ",")) . drop 1 $ dropWhile (/= [""]) contents
 | 
				
			||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
{-# OPTIONS_GHC -Wno-incomplete-patterns #-}
 | 
					{-# OPTIONS_GHC -Wno-incomplete-patterns #-}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module Day5.Puzzle2 (day5_2) where
 | 
					module Day05.Puzzle2 (day05_2) where
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import Data.List ((\\))
 | 
					import Data.List ((\\))
 | 
				
			||||||
import Data.List.Split (splitOn)
 | 
					import Data.List.Split (splitOn)
 | 
				
			||||||
@@ -22,8 +22,8 @@ sortOnRules rules (x : xs) = sortOnRules rules beforeArray ++ [x] ++ sortOnRules
 | 
				
			|||||||
    beforeArray = xs \\ afterArray
 | 
					    beforeArray = xs \\ afterArray
 | 
				
			||||||
    before = [p | (p, n) <- rules, n == x]
 | 
					    before = [p | (p, n) <- rules, n == x]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
day5_2 :: IO ()
 | 
					day05_2 :: IO ()
 | 
				
			||||||
day5_2 = do
 | 
					day05_2 = do
 | 
				
			||||||
  contents <- map (splitOn "|") . lines <$> readFile "input/day5.txt"
 | 
					  contents <- map (splitOn "|") . lines <$> readFile "input/day5.txt"
 | 
				
			||||||
  let rules = [(read x, read y) | [x, y] <- takeWhile (/= [""]) contents]
 | 
					  let rules = [(read x, read y) | [x, y] <- takeWhile (/= [""]) contents]
 | 
				
			||||||
      unsorted = filter (not . isSorted rules) . map (map read) $ concatMap (map (splitOn ",")) . drop 1 $ dropWhile (/= [""]) contents
 | 
					      unsorted = filter (not . isSorted rules) . map (map read) $ concatMap (map (splitOn ",")) . drop 1 $ dropWhile (/= [""]) contents
 | 
				
			||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
module Day6.Puzzle1 (day6_1) where
 | 
					module Day06.Puzzle1 (day06_1) where
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import Data.List (elemIndex, uncons)
 | 
					import Data.List (elemIndex, uncons)
 | 
				
			||||||
import Data.Maybe (fromJust, fromMaybe, isJust)
 | 
					import Data.Maybe (fromJust, fromMaybe, isJust)
 | 
				
			||||||
@@ -68,8 +68,8 @@ visitGrid (x, y) direction grid =
 | 
				
			|||||||
        then visitGrid nextPosition newDirection newGrid
 | 
					        then visitGrid nextPosition newDirection newGrid
 | 
				
			||||||
        else newGrid
 | 
					        else newGrid
 | 
				
			||||||
 | 
					
 | 
				
			||||||
day6_1 :: IO ()
 | 
					day06_1 :: IO ()
 | 
				
			||||||
day6_1 = do
 | 
					day06_1 = do
 | 
				
			||||||
  contents <- lines <$> readFile "input/day6.txt"
 | 
					  contents <- lines <$> readFile "input/day6.txt"
 | 
				
			||||||
  let (x, y) =
 | 
					  let (x, y) =
 | 
				
			||||||
        (\a b c d -> fst . fromJust $ uncons $ filter ((>= 0) . fst) [a, b, c, d])
 | 
					        (\a b c d -> fst . fromJust $ uncons $ filter ((>= 0) . fst) [a, b, c, d])
 | 
				
			||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
module Day6.Puzzle2 (day6_2) where
 | 
					module Day06.Puzzle2 (day06_2) where
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import Data.List (elemIndex, uncons)
 | 
					import Data.List (elemIndex, uncons)
 | 
				
			||||||
import Data.Maybe (fromJust, fromMaybe, isJust)
 | 
					import Data.Maybe (fromJust, fromMaybe, isJust)
 | 
				
			||||||
@@ -93,8 +93,8 @@ setGridObstacles startPosition grid =
 | 
				
			|||||||
  let positions = [(x, y) | x <- [0 .. (length grid - 1)], y <- [0 .. (length (fst . fromJust $ uncons grid) - 1)], (x, y) /= startPosition, getGridVal (x, y) grid == 'X']
 | 
					  let positions = [(x, y) | x <- [0 .. (length grid - 1)], y <- [0 .. (length (fst . fromJust $ uncons grid) - 1)], (x, y) /= startPosition, getGridVal (x, y) grid == 'X']
 | 
				
			||||||
   in zipWith (`markVisited` '#') positions (replicate (length positions) grid)
 | 
					   in zipWith (`markVisited` '#') positions (replicate (length positions) grid)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
day6_2 :: IO ()
 | 
					day06_2 :: IO ()
 | 
				
			||||||
day6_2 = do
 | 
					day06_2 = do
 | 
				
			||||||
  contents <- lines <$> readFile "input/day6.txt"
 | 
					  contents <- lines <$> readFile "input/day6.txt"
 | 
				
			||||||
  let (x, y) =
 | 
					  let (x, y) =
 | 
				
			||||||
        (\a b c d -> fst . fromJust $ uncons $ filter ((>= 0) . fst) [a, b, c, d])
 | 
					        (\a b c d -> fst . fromJust $ uncons $ filter ((>= 0) . fst) [a, b, c, d])
 | 
				
			||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
module Day7.Puzzle1 (day7_1) where
 | 
					module Day07.Puzzle1 (day07_1) where
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import Data.List (transpose)
 | 
					import Data.List (transpose)
 | 
				
			||||||
import Data.List.Split (splitOn)
 | 
					import Data.List.Split (splitOn)
 | 
				
			||||||
@@ -14,8 +14,8 @@ isSolvable cur (result, x : y : ys) =
 | 
				
			|||||||
    || isSolvable (cur * x + y) (result, ys)
 | 
					    || isSolvable (cur * x + y) (result, ys)
 | 
				
			||||||
    || isSolvable (cur * x * y) (result, ys)
 | 
					    || isSolvable (cur * x * y) (result, ys)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
day7_1 :: IO ()
 | 
					day07_1 :: IO ()
 | 
				
			||||||
day7_1 = do
 | 
					day07_1 = do
 | 
				
			||||||
  [x, y] <- transpose . map (splitOn ":") . lines <$> readFile "input/day7.txt"
 | 
					  [x, y] <- transpose . map (splitOn ":") . lines <$> readFile "input/day7.txt"
 | 
				
			||||||
  let results = map read x
 | 
					  let results = map read x
 | 
				
			||||||
      values = map read <$> map words y
 | 
					      values = map read <$> map words y
 | 
				
			||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
module Day7.Puzzle2 (day7_2) where
 | 
					module Day07.Puzzle2 (day07_2) where
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import Data.List (transpose)
 | 
					import Data.List (transpose)
 | 
				
			||||||
import Data.List.Split (splitOn)
 | 
					import Data.List.Split (splitOn)
 | 
				
			||||||
@@ -22,8 +22,8 @@ isSolvable cur (result, x : y : ys) =
 | 
				
			|||||||
    || isSolvable ((cur `concatInt` x) * y) (result, ys)
 | 
					    || isSolvable ((cur `concatInt` x) * y) (result, ys)
 | 
				
			||||||
    || isSolvable ((cur `concatInt` x) `concatInt` y) (result, ys)
 | 
					    || isSolvable ((cur `concatInt` x) `concatInt` y) (result, ys)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
day7_2 :: IO ()
 | 
					day07_2 :: IO ()
 | 
				
			||||||
day7_2 = do
 | 
					day07_2 = do
 | 
				
			||||||
  [x, y] <- transpose . map (splitOn ":") . lines <$> readFile "input/day7.txt"
 | 
					  [x, y] <- transpose . map (splitOn ":") . lines <$> readFile "input/day7.txt"
 | 
				
			||||||
  let results = map read x
 | 
					  let results = map read x
 | 
				
			||||||
      values = map read <$> map words y
 | 
					      values = map read <$> map words y
 | 
				
			||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
module Day8.Puzzle1 (day8_1) where
 | 
					module Day08.Puzzle1 (day08_1) where
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import Control.Applicative
 | 
					import Control.Applicative
 | 
				
			||||||
import Data.List (uncons)
 | 
					import Data.List (uncons)
 | 
				
			||||||
@@ -36,8 +36,8 @@ getAntinodes a b maxX maxY =
 | 
				
			|||||||
        then []
 | 
					        then []
 | 
				
			||||||
        else filter (\c -> isInside c maxX maxY) [(2 * xa - xb, 2 * ya - yb), (2 * xb - xa, 2 * yb - ya)]
 | 
					        else filter (\c -> isInside c maxX maxY) [(2 * xa - xb, 2 * ya - yb), (2 * xb - xa, 2 * yb - ya)]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
day8_1 :: IO ()
 | 
					day08_1 :: IO ()
 | 
				
			||||||
day8_1 = do
 | 
					day08_1 = do
 | 
				
			||||||
  contents <- lines <$> readFile "input/day8.txt"
 | 
					  contents <- lines <$> readFile "input/day8.txt"
 | 
				
			||||||
  let antennas = getAntennas contents
 | 
					  let antennas = getAntennas contents
 | 
				
			||||||
      x = length contents
 | 
					      x = length contents
 | 
				
			||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
module Day8.Puzzle2 (day8_2) where
 | 
					module Day08.Puzzle2 (day08_2) where
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import Control.Applicative
 | 
					import Control.Applicative
 | 
				
			||||||
import Data.Bifunctor (bimap)
 | 
					import Data.Bifunctor (bimap)
 | 
				
			||||||
@@ -47,8 +47,8 @@ getAntinodes a b maxX maxY =
 | 
				
			|||||||
            ++ takeWhile (\c -> isInside c maxX maxY) (generateCoords (coordinates a) (distX, distY))
 | 
					            ++ takeWhile (\c -> isInside c maxX maxY) (generateCoords (coordinates a) (distX, distY))
 | 
				
			||||||
            ++ takeWhile (\c -> isInside c maxX maxY) (generateCoords (coordinates b) (-distX, -distY))
 | 
					            ++ takeWhile (\c -> isInside c maxX maxY) (generateCoords (coordinates b) (-distX, -distY))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
day8_2 :: IO ()
 | 
					day08_2 :: IO ()
 | 
				
			||||||
day8_2 = do
 | 
					day08_2 = do
 | 
				
			||||||
  contents <- lines <$> readFile "input/day8.txt"
 | 
					  contents <- lines <$> readFile "input/day8.txt"
 | 
				
			||||||
  let antennas = getAntennas contents
 | 
					  let antennas = getAntennas contents
 | 
				
			||||||
      x = length contents
 | 
					      x = length contents
 | 
				
			||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
module Day9.Puzzle1 (day9_1) where
 | 
					module Day09.Puzzle1 (day09_1) where
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import Control.Applicative
 | 
					import Control.Applicative
 | 
				
			||||||
import Data.Char (digitToInt)
 | 
					import Data.Char (digitToInt)
 | 
				
			||||||
@@ -25,8 +25,8 @@ compact xs
 | 
				
			|||||||
checksum :: [Int] -> Int
 | 
					checksum :: [Int] -> Int
 | 
				
			||||||
checksum xs = sum $ zipWith (*) xs [0 ..]
 | 
					checksum xs = sum $ zipWith (*) xs [0 ..]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
day9_1 :: IO ()
 | 
					day09_1 :: IO ()
 | 
				
			||||||
day9_1 = do
 | 
					day09_1 = do
 | 
				
			||||||
  contents <- init <$> readFile "input/day9.txt"
 | 
					  contents <- init <$> readFile "input/day9.txt"
 | 
				
			||||||
  let diskMap = map digitToInt contents
 | 
					  let diskMap = map digitToInt contents
 | 
				
			||||||
  putStrLn $
 | 
					  putStrLn $
 | 
				
			||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
{-# OPTIONS_GHC -Wno-incomplete-patterns #-}
 | 
					{-# OPTIONS_GHC -Wno-incomplete-patterns #-}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module Day9.Puzzle2 (day9_2) where
 | 
					module Day09.Puzzle2 (day09_2) where
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import Data.Char (digitToInt)
 | 
					import Data.Char (digitToInt)
 | 
				
			||||||
import qualified Data.Foldable as F
 | 
					import qualified Data.Foldable as F
 | 
				
			||||||
@@ -62,8 +62,8 @@ tuplesToIntList disk =
 | 
				
			|||||||
checksum :: [Int] -> Int
 | 
					checksum :: [Int] -> Int
 | 
				
			||||||
checksum xs = sum $ zipWith (*) (maskMinus1 xs) [0 ..]
 | 
					checksum xs = sum $ zipWith (*) (maskMinus1 xs) [0 ..]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
day9_2 :: IO ()
 | 
					day09_2 :: IO ()
 | 
				
			||||||
day9_2 = do
 | 
					day09_2 = do
 | 
				
			||||||
  contents <- init <$> readFile "input/day9.txt"
 | 
					  contents <- init <$> readFile "input/day9.txt"
 | 
				
			||||||
  let disk = parseDiskMap $ map digitToInt contents
 | 
					  let disk = parseDiskMap $ map digitToInt contents
 | 
				
			||||||
      i = fromMaybe (-1) $ S.findIndexR (\x -> fst x /= -1) disk
 | 
					      i = fromMaybe (-1) $ S.findIndexR (\x -> fst x /= -1) disk
 | 
				
			||||||
							
								
								
									
										94
									
								
								src/Main.hs
									
									
									
									
									
								
							
							
						
						
									
										94
									
								
								src/Main.hs
									
									
									
									
									
								
							@@ -1,23 +1,23 @@
 | 
				
			|||||||
module Main (main) where
 | 
					module Main (main) where
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import Day1.Puzzle1
 | 
					import Day01.Puzzle1
 | 
				
			||||||
import Day1.Puzzle2
 | 
					import Day01.Puzzle2
 | 
				
			||||||
import Day2.Puzzle1
 | 
					import Day02.Puzzle1
 | 
				
			||||||
import Day2.Puzzle2
 | 
					import Day02.Puzzle2
 | 
				
			||||||
import Day3.Puzzle1
 | 
					import Day03.Puzzle1
 | 
				
			||||||
import Day3.Puzzle2
 | 
					import Day03.Puzzle2
 | 
				
			||||||
import Day4.Puzzle1
 | 
					import Day04.Puzzle1
 | 
				
			||||||
import Day4.Puzzle2
 | 
					import Day04.Puzzle2
 | 
				
			||||||
import Day5.Puzzle1
 | 
					import Day05.Puzzle1
 | 
				
			||||||
import Day5.Puzzle2
 | 
					import Day05.Puzzle2
 | 
				
			||||||
import Day6.Puzzle1
 | 
					import Day06.Puzzle1
 | 
				
			||||||
import Day6.Puzzle2
 | 
					import Day06.Puzzle2
 | 
				
			||||||
import Day7.Puzzle1
 | 
					import Day07.Puzzle1
 | 
				
			||||||
import Day7.Puzzle2
 | 
					import Day07.Puzzle2
 | 
				
			||||||
import Day8.Puzzle1
 | 
					import Day08.Puzzle1
 | 
				
			||||||
import Day8.Puzzle2
 | 
					import Day08.Puzzle2
 | 
				
			||||||
import Day9.Puzzle1
 | 
					import Day09.Puzzle1
 | 
				
			||||||
import Day9.Puzzle2
 | 
					import Day09.Puzzle2
 | 
				
			||||||
import Day10.Puzzle1
 | 
					import Day10.Puzzle1
 | 
				
			||||||
import Day11.Puzzle1
 | 
					import Day11.Puzzle1
 | 
				
			||||||
import Day11.Puzzle2
 | 
					import Day11.Puzzle2
 | 
				
			||||||
@@ -30,32 +30,32 @@ import System.Environment (getArgs)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
main :: IO ()
 | 
					main :: IO ()
 | 
				
			||||||
main = do
 | 
					main = do
 | 
				
			||||||
    args <- getArgs
 | 
					  args <- getArgs
 | 
				
			||||||
    case args of
 | 
					  case args of
 | 
				
			||||||
         "1":"1":_  -> day1_1
 | 
					    "1" : "1" : _ -> day01_1
 | 
				
			||||||
         "1":"2":_  -> day1_2
 | 
					    "1" : "2" : _ -> day01_2
 | 
				
			||||||
         "2":"1":_  -> day2_1
 | 
					    "2" : "1" : _ -> day02_1
 | 
				
			||||||
         "2":"2":_  -> day2_2
 | 
					    "2" : "2" : _ -> day02_2
 | 
				
			||||||
         "3":"1":_  -> day3_1
 | 
					    "3" : "1" : _ -> day03_1
 | 
				
			||||||
         "3":"2":_  -> day3_2
 | 
					    "3" : "2" : _ -> day03_2
 | 
				
			||||||
         "4":"1":_  -> day4_1
 | 
					    "4" : "1" : _ -> day04_1
 | 
				
			||||||
         "4":"2":_  -> day4_2
 | 
					    "4" : "2" : _ -> day04_2
 | 
				
			||||||
         "5":"1":_  -> day5_1
 | 
					    "5" : "1" : _ -> day05_1
 | 
				
			||||||
         "5":"2":_  -> day5_2
 | 
					    "5" : "2" : _ -> day05_2
 | 
				
			||||||
         "6":"1":_  -> day6_1
 | 
					    "6" : "1" : _ -> day06_1
 | 
				
			||||||
         "6":"2":_  -> day6_2
 | 
					    "6" : "2" : _ -> day06_2
 | 
				
			||||||
         "7":"1":_  -> day7_1
 | 
					    "7" : "1" : _ -> day07_1
 | 
				
			||||||
         "7":"2":_  -> day7_2
 | 
					    "7" : "2" : _ -> day07_2
 | 
				
			||||||
         "8":"1":_  -> day8_1
 | 
					    "8" : "1" : _ -> day08_1
 | 
				
			||||||
         "8":"2":_  -> day8_2
 | 
					    "8" : "2" : _ -> day08_2
 | 
				
			||||||
         "9":"1":_  -> day9_1
 | 
					    "9" : "1" : _ -> day09_1
 | 
				
			||||||
         "9":"2":_  -> day9_2
 | 
					    "9" : "2" : _ -> day09_2
 | 
				
			||||||
         "10":"1":_ -> day10_1
 | 
					    "10" : "1" : _ -> day10_1
 | 
				
			||||||
         "11":"1":_ -> day11_1
 | 
					    "11" : "1" : _ -> day11_1
 | 
				
			||||||
         "11":"2":_ -> day11_2
 | 
					    "11" : "2" : _ -> day11_2
 | 
				
			||||||
         "12":"1":_ -> day12_1
 | 
					    "12" : "1" : _ -> day12_1
 | 
				
			||||||
         "13":"1":_ -> day13_1
 | 
					    "13" : "1" : _ -> day13_1
 | 
				
			||||||
         "13":"2":_ -> day13_2
 | 
					    "13" : "2" : _ -> day13_2
 | 
				
			||||||
         "14":"1":_ -> day14_1
 | 
					    "14" : "1" : _ -> day14_1
 | 
				
			||||||
         "15":"1":_ -> day15_1
 | 
					    "15" : "1" : _ -> day15_1
 | 
				
			||||||
         _          -> error "Not implemented"
 | 
					    _ -> error "Not implemented"
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user