Day 25, Part 1
This commit is contained in:
parent
934e5971ef
commit
459b15b2dd
@ -7,4 +7,4 @@ I started learning Haskell very recently, and I just learned this year that Adve
|
|||||||
|02 |★ ★ |07 |★ ★ |12 |★ |17 |★ ★ |22 |★ |
|
|02 |★ ★ |07 |★ ★ |12 |★ |17 |★ ★ |22 |★ |
|
||||||
|03 |★ ★ |08 |★ ★ |13 |★ ★ |18 |★ ★ |23 |★ |
|
|03 |★ ★ |08 |★ ★ |13 |★ ★ |18 |★ ★ |23 |★ |
|
||||||
|04 |★ ★ |09 |★ ★ |14 |★ ★ |19 |★ |24 |★ |
|
|04 |★ ★ |09 |★ ★ |14 |★ ★ |19 |★ |24 |★ |
|
||||||
|05 |★ ★ |10 |★ ★ |15 |★ |20 | |25 | |
|
|05 |★ ★ |10 |★ ★ |15 |★ |20 | |25 |★ |
|
||||||
|
@ -60,4 +60,5 @@ executable adventofcode2024
|
|||||||
Day22
|
Day22
|
||||||
Day23
|
Day23
|
||||||
Day24
|
Day24
|
||||||
|
Day25
|
||||||
Graph
|
Graph
|
||||||
|
32
src/Day25.hs
Normal file
32
src/Day25.hs
Normal 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
|
@ -22,6 +22,7 @@ import Day19 (day19_1)
|
|||||||
import Day22 (day22_1)
|
import Day22 (day22_1)
|
||||||
import Day23 (day23_1)
|
import Day23 (day23_1)
|
||||||
import Day24 (day24_1)
|
import Day24 (day24_1)
|
||||||
|
import Day25 (day25_1)
|
||||||
import System.Environment (getArgs)
|
import System.Environment (getArgs)
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
@ -110,6 +111,7 @@ main = do
|
|||||||
"22" : "1" : _ -> day22_1
|
"22" : "1" : _ -> day22_1
|
||||||
"23" : "1" : _ -> day23_1
|
"23" : "1" : _ -> day23_1
|
||||||
"24" : "1" : _ -> day24_1
|
"24" : "1" : _ -> day24_1
|
||||||
|
"25" : "1" : _ -> day25_1
|
||||||
"all" : _ -> do
|
"all" : _ -> do
|
||||||
day01_1
|
day01_1
|
||||||
day01_2
|
day01_2
|
||||||
@ -148,4 +150,5 @@ main = do
|
|||||||
day22_1
|
day22_1
|
||||||
day23_1
|
day23_1
|
||||||
day24_1
|
day24_1
|
||||||
|
day25_1
|
||||||
_ -> error "Not implemented"
|
_ -> error "Not implemented"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user