Day 25, Part 1

This commit is contained in:
Daniele Fucini
2024-12-25 09:57:38 +01:00
parent 934e5971ef
commit 459b15b2dd
4 changed files with 37 additions and 1 deletions

32
src/Day25.hs Normal file
View File

@@ -0,0 +1,32 @@
{-# OPTIONS_GHC -Wno-x-partial #-}
module Day25 (day25_1) where
import Control.Monad (guard)
import Data.List (transpose)
import Data.List.Split (splitOn)
parseSchematics :: [String] -> [Int]
parseSchematics s =
let s' = transpose . init $ tail s
in map (length . filter (== '#')) s'
keyLockCombinations :: [[Int]] -> [[Int]] -> [[Int]]
keyLockCombinations keys locks = do
key <- keys
lock <- locks
guard $ all (< 6) $ zipWith (+) key lock
return $ zipWith (+) key lock
day25_1 :: IO ()
day25_1 = do
contents <- lines <$> readFile "input/day25.txt"
let schematics = splitOn [""] contents
locks = map parseSchematics $ filter (\x -> head x == "#####" && last x == ".....") schematics
keys = map parseSchematics $ filter (\x -> head x == "....." && last x == "#####") schematics
putStrLn $
"Day 25, Puzzle 1 solution: "
++ show (length $ keyLockCombinations keys locks)
print . length $ keyLockCombinations keys locks