Day 23, Part 1
This commit is contained in:
parent
93ee53f0fe
commit
588b1e212f
@ -5,6 +5,6 @@ I started learning Haskell very recently, and I just learned this year that Adve
|
||||
|---|-----|---|-----|---|-----|---|-----|---|-----|
|
||||
|01 |★ ★ |06 |★ ★ |11 |★ ★ |16 |★ |21 | |
|
||||
|02 |★ ★ |07 |★ ★ |12 |★ |17 |★ ★ |22 |★ |
|
||||
|03 |★ ★ |08 |★ ★ |13 |★ ★ |18 |★ ★ |23 | |
|
||||
|03 |★ ★ |08 |★ ★ |13 |★ ★ |18 |★ ★ |23 |★ |
|
||||
|04 |★ ★ |09 |★ ★ |14 |★ ★ |19 |★ |24 | |
|
||||
|05 |★ ★ |10 |★ ★ |15 |★ |20 | |25 | |
|
||||
|
@ -58,4 +58,5 @@ executable adventofcode2024
|
||||
Day18
|
||||
Day19
|
||||
Day22
|
||||
Day23
|
||||
Graph
|
||||
|
@ -50,5 +50,4 @@ day16_1 = do
|
||||
(mazeMap, nRow, nCol) <- parseInput
|
||||
let (mazeGraph, start, end) = getMazeGraph mazeMap nRow nCol
|
||||
shortestPaths = [findShortestPath mazeGraph start e | e <- end]
|
||||
-- putStrLn $ "Day 16, Puzzle 1 solution: " ++ show (findShortestPath mazeGraph start end)
|
||||
putStrLn $ "Day 16, Puzzle 1 solution: " ++ show (minimum shortestPaths)
|
||||
|
40
src/Day23.hs
Normal file
40
src/Day23.hs
Normal file
@ -0,0 +1,40 @@
|
||||
module Day23 (day23_1) where
|
||||
|
||||
import Control.Monad
|
||||
import Data.Containers.ListUtils (nubOrd)
|
||||
import Data.List (nub, sort)
|
||||
import Data.List.Split (splitOn)
|
||||
|
||||
startsWithT :: String -> Bool
|
||||
startsWithT [] = False
|
||||
startsWithT (x : _)
|
||||
| x == 't' = True
|
||||
| otherwise = False
|
||||
|
||||
getConns3 :: [[String]] -> [[String]]
|
||||
getConns3 connections = do
|
||||
conn1 <- connections
|
||||
conn2 <- connections
|
||||
|
||||
guard $
|
||||
conn1 /= conn2
|
||||
&& length (nub (conn1 ++ conn2)) == 3
|
||||
&& any startsWithT (conn1 ++ conn2)
|
||||
|
||||
conn3 <- connections
|
||||
|
||||
guard $
|
||||
conn1 /= conn3
|
||||
&& conn2 /= conn3
|
||||
&& length (nub (conn1 ++ conn2 ++ conn3)) == 3
|
||||
&& any startsWithT (conn1 ++ conn2 ++ conn3)
|
||||
|
||||
return . nub $ conn1 ++ conn2 ++ conn3
|
||||
|
||||
day23_1 :: IO ()
|
||||
day23_1 = do
|
||||
contents <- lines <$> readFile "input/day23.txt"
|
||||
let connections = map (splitOn "-") contents
|
||||
putStrLn $
|
||||
"Day 23, Puzzle 1 solution: "
|
||||
++ show (length . nubOrd . map sort $ getConns3 connections)
|
@ -20,6 +20,7 @@ import Day17 (day17_1, day17_2)
|
||||
import Day18 (day18_1, day18_2)
|
||||
import Day19 (day19_1)
|
||||
import Day22 (day22_1)
|
||||
import Day23 (day23_1)
|
||||
import System.Environment (getArgs)
|
||||
|
||||
main :: IO ()
|
||||
@ -106,6 +107,7 @@ main = do
|
||||
day18_2
|
||||
"19" : "1" : _ -> day19_1
|
||||
"22" : "1" : _ -> day22_1
|
||||
"23" : "1" : _ -> day23_1
|
||||
"all" : _ -> do
|
||||
day01_1
|
||||
day01_2
|
||||
@ -142,4 +144,5 @@ main = do
|
||||
day18_2
|
||||
day19_1
|
||||
day22_1
|
||||
day23_1
|
||||
_ -> error "Not implemented"
|
||||
|
Loading…
x
Reference in New Issue
Block a user