-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday-12-springs.hs
65 lines (59 loc) · 1.33 KB
/
day-12-springs.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
module Main where
import AoC
import Control.Exception (assert)
import Data.List (sort)
solve :: [String] -> Int -> Int
solve inp = \case
1 -> part1
2 -> part2
where
part1 = 0
part2 = 0
tests = map sort [
-- f [] "?",
-- f [1] "?",
-- f [1] "#",
-- f [1] "??",
-- f [1] "?.?",
-- f [1] "?.??",
-- f [2] "?#",
f [1,1] "?.?"
-- f [1,1,3] "???.###"
]
expected = map sort [
-- ["."],
-- ["#"],
-- ["#"],
-- ["#.", ".#"],
-- ["#..", "..#"],
-- ["#...", "..#.", "...#"],
["#.#"]
-- ["#.#.###"]
]
runAllTests = assert (tests == expected) ()
f :: [Int] -> String -> [String]
-- f ns ss | traceShow (ns,ss) False = undefined
f [] ss =
case ss of
[] -> [[]]
_ -> f [0] ss
f ns [] =
case ns of
[0] -> [[]]
_ -> [] -- deadend: no place but some springs to place left
f ns@(x:xs) ts@(s:ss) = case s of
'.' -> map ('.' :) $ f ns ss
'#' -> map ('#' :) $ f (x-1:xs) ss
'?' ->
case x of
0 -> map ('.' :) $ f xs ss
_ -> map ('.' :) (f ns ss) ++
map ('#' :) (f (x-1:xs) ss)
-- (s':_) -> case s' of -- lookahead
-- '.' -> case x of
-- 0 -> case xs of
-- [] -> map ('.' :) $ f ns ss
-- (x':_) -> case x' of
-- 0 -> map ('.' :) $ f ns ss
main :: IO ()
main = defaultMain solve