Skip to content

Commit 1d234f9

Browse files
committed
feat(2024/Day25)
1 parent 7320112 commit 1d234f9

File tree

5 files changed

+4116
-0
lines changed

5 files changed

+4116
-0
lines changed

2024/Day25/Day25.hs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
module Main where
2+
3+
import Data.Bits
4+
import Data.List
5+
import Data.List.Split
6+
import Data.List.Unique
7+
import Data.Matrix (Matrix, (!))
8+
import Data.Matrix qualified as Mat
9+
import Data.Set (Set)
10+
import Data.Set qualified as S
11+
import Data.Tuple.Extra
12+
import Debug.Trace
13+
import System.Environment
14+
import Text.Regex.TDFA ((=~))
15+
-- TODO: Cleanup imports after day done
16+
17+
type Input = ([[Int]], [[Int]])
18+
type Output = Int
19+
20+
parseInput :: String -> Input
21+
parseInput input = (locks, keys)
22+
where
23+
inputs = splitOn "\n\n" input
24+
filterOut c = map transpose $ filter (\e -> all (== c) $ head e) $ map lines inputs
25+
findHeights c = map (map (((+) (-1)) . length . c))
26+
locks = findHeights (takeWhile (== '#')) $ filterOut '#'
27+
keys = findHeights (dropWhile (== '.')) $ filterOut '.'
28+
29+
fit :: [Int] -> [Int] -> Bool
30+
fit k l = all (<= 5) . map (\(a, b) -> a+b) $ zip k l
31+
32+
part1 :: Input -> Output
33+
part1 (locks, keys) = length [(key, lock) | key<-keys, lock<-locks, fit key lock]
34+
35+
main :: IO ()
36+
main = do
37+
args <- getArgs
38+
content <- readFile (last args)
39+
let input = parseInput content
40+
41+
-- print input
42+
43+
print $ part1 input

2024/Day25/Makefile

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
CONTAINER_NAME=haskell-aoc
2+
SRC=./Day25.hs
3+
TARGET=Day25
4+
all: $(TARGET)
5+
6+
$(TARGET): $(SRC)
7+
ghc -O3 $(SRC)
8+
9+
profile: $(SRC)
10+
11+
12+
clean:
13+
$(RM) ./Day25 ./Day25.o ./Day25.hi
14+
15+
setup: $(SRC)
16+
docker cp $(SRC) $(CONTAINER_NAME):/home/haskell/Main.hs
17+
docker cp input.txt $(CONTAINER_NAME):/home/haskell/input.txt
18+
docker cp shortinput.txt $(CONTAINER_NAME):/home/haskell/shortinput.txt
19+
20+
profiling: setup
21+
docker exec -it $(CONTAINER_NAME) cabal build --enable-profiling
22+
docker exec -it $(CONTAINER_NAME) ./profile input.txt
23+
24+
run: setup
25+
docker exec -it $(CONTAINER_NAME) cabal build
26+
docker exec -it $(CONTAINER_NAME) ./run input.txt
27+
28+
.PHONY: all $(TARGET) clean setup profiling run

0 commit comments

Comments
 (0)