diff options
-rw-r--r-- | aoc.cabal | 10 | ||||
-rw-r--r-- | execs/Day10.hs | 4 | ||||
-rw-r--r-- | execs/Day11.hs | 48 | ||||
-rw-r--r-- | input/11 | 94 | ||||
-rw-r--r-- | input/11sample | 10 | ||||
-rw-r--r-- | input/11sample2 | 9 | ||||
-rw-r--r-- | lib/Utils.hs | 44 |
7 files changed, 198 insertions, 21 deletions
@@ -19,8 +19,8 @@ extra-source-files: CHANGELOG.md | |||
19 | library | 19 | library |
20 | hs-source-dirs: lib | 20 | hs-source-dirs: lib |
21 | default-language: Haskell2010 | 21 | default-language: Haskell2010 |
22 | build-depends: base | 22 | build-depends: base, containers |
23 | exposed-modules: Utils | 23 | exposed-modules: Utils |
24 | 24 | ||
25 | executable Day01 | 25 | executable Day01 |
26 | main-is: Day01.hs | 26 | main-is: Day01.hs |
@@ -81,3 +81,9 @@ executable Day10 | |||
81 | build-depends: base, aoc, containers, monad-memo | 81 | build-depends: base, aoc, containers, monad-memo |
82 | default-language: Haskell2010 | 82 | default-language: Haskell2010 |
83 | hs-source-dirs: execs | 83 | hs-source-dirs: execs |
84 | |||
85 | executable Day11 | ||
86 | main-is: Day11.hs | ||
87 | build-depends: base, aoc, containers | ||
88 | default-language: Haskell2010 | ||
89 | hs-source-dirs: execs | ||
diff --git a/execs/Day10.hs b/execs/Day10.hs index c42a550..40d3d61 100644 --- a/execs/Day10.hs +++ b/execs/Day10.hs | |||
@@ -16,9 +16,7 @@ diffs s = product $ ($ q s) <$> [howMany (==1), howMany (==3)] | |||
16 | combos top s = startEvalMemo $ go 0 | 16 | combos top s = startEvalMemo $ go 0 |
17 | where go c | 17 | where go c |
18 | | c == top = return 1 | 18 | | c == top = return 1 |
19 | | otherwise = do | 19 | | otherwise = sum <$> mapM (memo go) (filter (`elem` s) $ map (+c) [1,2,3]) |
20 | let cs = filter (`elem` s) $ map (+c) [1,2,3] | ||
21 | sum <$> mapM (memo go) cs | ||
22 | 20 | ||
23 | main :: IO () | 21 | main :: IO () |
24 | main = do | 22 | main = do |
diff --git a/execs/Day11.hs b/execs/Day11.hs new file mode 100644 index 0000000..e2f138b --- /dev/null +++ b/execs/Day11.hs | |||
@@ -0,0 +1,48 @@ | |||
1 | module Main where | ||
2 | |||
3 | import Utils | ||
4 | import Data.List (sortOn) | ||
5 | import Data.Map (Map, (!)) | ||
6 | import qualified Data.Map as Map | ||
7 | import Data.Maybe | ||
8 | |||
9 | dirs = [ (-1,-1), (0,-1), (1,-1) | ||
10 | , (-1, 0), (1, 0) | ||
11 | , (-1, 1), (0, 1), (1, 1) | ||
12 | ] | ||
13 | |||
14 | adjs1 m pt = howMany (== '#') $ mapMaybe ((`Map.lookup` m) . add pt) dirs | ||
15 | |||
16 | inGrid (x, y) w h = x < w && x >= 0 && y < h && y >= 0 | ||
17 | adjs2 grid pt w h = howMany ((== '#') . head) | ||
18 | $ filter (not . null) | ||
19 | $ map (dropWhile (== '.') | ||
20 | . map (grid !) | ||
21 | . takeWhile (inside (0, 0) (w-1, h-1)) | ||
22 | . map ($ pt) | ||
23 | . repeatF | ||
24 | . add) | ||
25 | dirs | ||
26 | |||
27 | rule1 w h m pt@(x, y) = if as == 0 then '#' else 'L' | ||
28 | where as = adjs2 m pt w h | ||
29 | |||
30 | rule2 w h m pt@(x, y) = if as >= 5 then 'L' else '#' | ||
31 | where as = adjs2 m pt w h | ||
32 | |||
33 | doStep w h m = Map.mapWithKey fn m | ||
34 | where fn k 'L' = rule1 w h m k | ||
35 | fn k '#' = rule2 w h m k | ||
36 | fn k '.' = '.' | ||
37 | |||
38 | stepWhile prev w h | ||
39 | | prev == next = next | ||
40 | | otherwise = stepWhile next w h | ||
41 | where next = doStep w h prev | ||
42 | |||
43 | main :: IO () | ||
44 | main = do | ||
45 | n <- readFile "input/11" | ||
46 | let (grid, width, height) = makeGrid n | ||
47 | let solve1 = stepWhile grid width height | ||
48 | print $ howMany ((== '#') . snd) $ Map.toList solve1 | ||
diff --git a/input/11 b/input/11 new file mode 100644 index 0000000..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LLLLLL.LLLLLLLLLLLL.LLLLLLL.LLLLLLLLLL.LLLL.LLLL.LLLL.LLLLL | ||
12 | LLLLLL.LLL.L..LLLLLLLLL.LLLLLLLLLLL.LLLLLLLLLLLLLLLL.LLLLL.LLLLLLL.LLLLL.LLL.LLLLLLLLLLLLLLL | ||
13 | LLLLLLLLLLLL.LLLL.LLLLL.LLLLLLLL.LLLLLL.LL.LLL.LLLLL.LLLLL.LLLLLLL.LLLLLLLLLLL.LL.LLLL.LLLLL | ||
14 | LLLLLL.LLLLLLLLLL.LLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLL.LLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL | ||
15 | LLLLLL.LLLLLLLLLL.LLLLL.LLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLL.LLLLLLL.LLLLLLLLL.LLLL.LLLLL.LLLL | ||
16 | .............LLL...LL...L...LL...L...LL..........L.LLLLLL..L.L..L..LL..LLL.......L......L... | ||
17 | LLLLLL.LLLLL.LLLL.LLLLL.LLLLLLLL.LLLLLLLL..LLLLLLLLL.LLLLLLLLL.LLL.LLLL.LLLLLLLLL.LLLL.LLLLL | ||
18 | LLLLLLLLLLLL.L.LLLLLLLL.LLLLLLLL.LLLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLL.LLLL.LLLL.LLLL.LLLL.LLLL. | ||
19 | LLLLLLLLLLLL.LLLLLLLLLL.LLLLLLLLLLLLLLLLLLLL.LL.LLLL.LLLLLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLLLL | ||
20 | LLLLLLLLLLLLLLLLL.LLLLL.LLLLLLLL.LLLLLL.LL.LLLLLLLLL.LLLLL.LLLL.LL.LLLL.LLLLLLLLL.LLLLLLLLLL | ||
21 | LLLLLL.LLLLL.LLLL.LLLLL.LLLLLLLL.LLLL.LLLL.LLLLLLLLL.LLLLL.LLLLLLL.LLLL.LLLLLLLLL.LLLL.LLLLL | ||
22 | LL...L.L....LL..L.........L...L....LLL......L.L..L..L...L........L..LLL.....L.LL.LL..LL..L.. | ||
23 | LLLLLL.LLLLL.LLLLL.LLLL.LL.LLLLL.LLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLL.LLLL.LLLL.LLLL.LLLL.LLLLL | ||
24 | LLLLLLLLLLLL.LLLL.LLLLL.LLLLLLLL.LLLL.LLLL.LLLLLLLLL.LLLLL.LLLLLLLLLLLL.LLLL.LLLL.LLLL.LLLLL | ||
25 | LLLLLL.LLLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLL.LLLL.LLLL.LLLLLLLLLLLLLLL | ||
26 | LLLLLL.LLLLLLLLLL.LLLLLLLLLLLLLL.LLLLLLLLL.LL.LLLLLL.LLL.L.LLLLLLL.LLLL.LLLL.LLLL.LLLL.LLLLL | ||
27 | LLLLLL.LLLLL.LLLL.LLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLL.LL.LL.LLLLLLL.LLLL.LLLLLLLLL..LLL.LLLLL | ||
28 | LLLLLLLLLLLL.LLLL.LLLLL.LLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLL.L.LLLLLLL.LLLLLLLLLLLLLL.LLLL.LLLLL | ||
29 | ...L.....L.L....L.LL...L..LLLL.L...L..L......L...L.L.L...L..L...LL.....L.L..L..L.L.L.....L.. | ||
30 | LLLLLL.LLLLL.LLLL.LLL..LLLLLLLLL.LLLLLLLLLLLLLLLLLLL.LLLLL.LLLLLLLLLLLL.LLLL.LLLL.LLLL.LLLLL | ||
31 | .LLLLL.LLLLL.LLLLLLLLLL.LLLLLLLL.LLLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLLLL | ||
32 | LLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLL.LLLLLLLLL.LLLLL.LL.LLLL.LLLL.LLLL.LLLL.LLLL.L.LLL | ||
33 | LLLLLL.LLLLLLLLLLLLLLLL.L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.LL | ||
55 | LLLLLL..LLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLL.LLLL.LLLL.LLLL.LLLL.LLLLL | ||
56 | .L.........L.L...L.....L..LL..LLL.L........L.LL.....L...L.....LL.....LLL....LLLL.L.L......L. | ||
57 | LLLLLLLLLLLL.LLLL.LLLLL.LLLLLLLL.LLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLL.L.LL.LLLLLLLLL.LLLLLLLLLL | ||
58 | LLLLLLLLLLLLLLLLL.LLLLL.LLLLLLLLLLLLLLLLLL.LLLLLLLLL.LLLLL.LLLLLLLLLLLL.LLLLLLLLLLLLLL.LLL.L | ||
59 | LLLLLL.LLLLL.LLLLLLLLLL.LLLLLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLL.LLLL.LLLL.LLLL.LLLLLLLLLL | ||
60 | LLLLLL.LLLLL.LLLL.LLLLL.LLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLL.LLLLLLLLLLLL.LLLLLLLLLLLLLL.LLLLL | ||
61 | LLLLLL.LLLLL.LLLL.LLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLL.LLLLLLL.LLLL.LLLLLLLLL.LLLLLLLLLL | ||
62 | ....LL.L..L....L..L.L.....L...L..LL....LLL..L.....L.L.....L.LL...L.LLL.LL.....LL..LLL....L.L | ||
63 | LLLLLLLLLLLLLLLLL.LLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLL.LLLL.LLLL.LLLL.LLLL.LLLLL | ||
64 | .LLLLLLLLLLL.LLLL.LLLLL.LLLLLLLL.LLLLLLLLL..LLLLLLLL.LLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLL.LLLLL | ||
65 | LLLLLLLL.LLL.LLLLLLL.LL.LLLLLLLL.LLLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLLLLLLL.LLLLLLLL..LLLLLLLLLL | ||
66 | LLLLLLLLLLLL.LLLLLLLLLL.LLLLLLLL.LLLLLLLLL.LLLLLLLLL.LLLLL.LLLLLLL.LLLLLLLLL.LLLLLLLLL.LLLLL | ||
67 | ..L...LL.L.......L..L...L.L.L..L.L.LL...L....LLL.....L.......L...LL......L.LL...L.L...L..... | ||
68 | LLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLLLLLLLL.LL.LLLLLLLLLLLL.LLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLL | ||
69 | LLLLLL.LLLLL.LLLL.LLLLL.LLLLLLLLLLLLLLL.LL.LLLLLLLLLLLLLLL.LL.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL | ||
70 | LLLLLLLLLLLL.LLLL.LLLLL.LLLLLLLL.LLLLL.LLL.LLLLLLLLL.LLLLL.LLLLLLL.LLLLLLLLLLLLLL.LLLL.LLLLL | ||
71 | LLLLLLLLLLLLLLLLL.LLLLL.LLLLLLLL.LLLLLLLLL.LLLLLLLLL.LLLLL.LLLLLLL.LLLL.LLLL.LLLLLLL.L.LLLLL | ||
72 | LLLLLL..LLLL.LLLL.LLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLL.L.LLLLL.LLLLLLL.LLLLLLLLL.LLLL.LLLL.LLLLL | ||
73 | LLLLLL.LLLLL.LLLL.LLLLLLLL.LLLLL.LLLLLLLLL.LLLLLLLLL.LLLLL.LLLLLLLLLLLL.LLLL.LLLL.LLLL.LLLLL | ||
74 | LL.LLL.LLLLL.LLLL.LLLLL.LLLLLLLLLLLLLLLLLL.LLLLLLLLL.LLLLL.LLLLLLLLLLLL.LLLL.LLLL.LLLL.LLLLL | ||
75 | LLLLLL.LLLLL.LL.L.LLLLL.LLLLLLLL.LLLLLLLLLLLLLLLLLLL.LLLLL.LLLLLLL.LLLL.LLLL.LLLL.LLLL.LLLLL | ||
76 | ..L..L..LL..L...L....L.....LL.....LL..........L...L.L....L.........L......LL.....L.LL...LL.. | ||
77 | LLLLLL.LLLLL.LLLLL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| ||
88 | L.LLLL.LL.LL.LLLL.LLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLLL.LLLLL.LLLLLLL.LLLL.LLLL.LLLL.LLLL.LLLLL | ||
89 | LLLLLL.LLLLLLLLLL.LLLLL.LLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLL.LLLLLLLLL.LLLL..LLLL | ||
90 | LLLLLL.LLLLLLLLLL.LLLLL.LLLLLLLL.LLLLLLLLL.LLLLLLLLL.LLLLL.LLLLLLLLLLLL.LLLL.LLLLLLL.L.LLLLL | ||
91 | LLLLLL.LLLLL.LLLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLLLLLLLL.LLLLLLLLLLLLL.LLLL.LLLL.LLLL.LLLL.LLLLL | ||
92 | LL.LLLLLLLLL.LLLL.LLLLL.LLLLLLLL.LLLLLLLLL..LLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLL.LLLLL | ||
93 | LLLLLL.LLLLL.LLLL.LLLLL.L.LLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLL.LLLLLLL.LLLL.LLLL.LLLLLLLLLLLLLLL | ||
94 | LLLLLLLLLLLL.LLLL.LLLLL.LLLLLLLL.LL.LLLLLLL.LLLLLLLL.LLLLL.LLLLLLLLLLLL.LLLL.LLLLLLLLL.LLLLL | ||
diff --git a/input/11sample b/input/11sample new file mode 100644 index 0000000..1beaede --- /dev/null +++ b/input/11sample | |||
@@ -0,0 +1,10 @@ | |||
1 | L.LL.LL.LL | ||
2 | LLLLLLL.LL | ||
3 | L.L.L..L.. | ||
4 | LLLL.LL.LL | ||
5 | L.LL.LL.LL | ||
6 | L.LLLLL.LL | ||
7 | ..L.L..... | ||
8 | LLLLLLLLLL | ||
9 | L.LLLLLL.L | ||
10 | L.LLLLL.LL | ||
diff --git a/input/11sample2 b/input/11sample2 new file mode 100644 index 0000000..a486e35 --- /dev/null +++ b/input/11sample2 | |||
@@ -0,0 +1,9 @@ | |||
1 | .......#. | ||
2 | ...#..... | ||
3 | .#....... | ||
4 | ......... | ||
5 | ..#L....# | ||
6 | ....#.... | ||
7 | ......... | ||
8 | #........ | ||
9 | ...#..... | ||
diff --git a/lib/Utils.hs b/lib/Utils.hs index 61c4e49..6358230 100644 --- a/lib/Utils.hs +++ b/lib/Utils.hs | |||
@@ -1,19 +1,11 @@ | |||
1 | module Utils ( binaryToInt | 1 | module Utils where |
2 | , countElem | ||
3 | , xor | ||
4 | , right | ||
5 | , bet | ||
6 | , (&+) | ||
7 | , howMany | ||
8 | , sublists | ||
9 | , windows | ||
10 | ) where | ||
11 | |||
12 | import Data.Char (digitToInt) | ||
13 | import Control.Monad | ||
14 | import Data.Either | ||
15 | import Data.List (inits, tails) | ||
16 | 2 | ||
3 | import Data.Char (digitToInt) | ||
4 | import Control.Monad | ||
5 | import Data.Either | ||
6 | import Data.List (inits, tails) | ||
7 | import Data.Map (Map) | ||
8 | import qualified Data.Map as Map | ||
17 | 9 | ||
18 | binaryToInt :: String -> Int | 10 | binaryToInt :: String -> Int |
19 | binaryToInt = foldl (\a x -> a * 2 + digitToInt x) 0 | 11 | binaryToInt = foldl (\a x -> a * 2 + digitToInt x) 0 |
@@ -28,13 +20,16 @@ right :: Either a b -> b | |||
28 | right (Right b) = b | 20 | right (Right b) = b |
29 | right _ = undefined | 21 | right _ = undefined |
30 | 22 | ||
31 | bet :: Int -> (Int, Int) -> Bool | ||
32 | bet k (l, u) = k >= l && k <= u | 23 | bet k (l, u) = k >= l && k <= u |
24 | bet' k (l, u) = k > l && k < u | ||
33 | 25 | ||
34 | -- combine filter predicates | 26 | -- combine filter predicates |
35 | (&+) :: (a -> Bool) -> (a -> Bool) -> (a -> Bool) | 27 | (&+) :: (a -> Bool) -> (a -> Bool) -> (a -> Bool) |
36 | (&+) = liftM2 (&&) | 28 | (&+) = liftM2 (&&) |
37 | 29 | ||
30 | (|+) :: (a -> Bool) -> (a -> Bool) -> (a -> Bool) | ||
31 | (|+) = liftM2 (||) | ||
32 | |||
38 | howMany :: (a -> Bool) -> [a] -> Int | 33 | howMany :: (a -> Bool) -> [a] -> Int |
39 | howMany predicate = length . filter predicate | 34 | howMany predicate = length . filter predicate |
40 | 35 | ||
@@ -49,3 +44,20 @@ kadane = go 0 0 | |||
49 | where go :: Int -> Int -> [Int] -> Int | 44 | where go :: Int -> Int -> [Int] -> Int |
50 | go best _ [] = best | 45 | go best _ [] = best |
51 | go best current (l:ls) = go (max best (current + l)) (max current (current + l)) ls | 46 | go best current (l:ls) = go (max best (current + l)) (max current (current + l)) ls |
47 | |||
48 | -- tuple stuff | ||
49 | |||
50 | add (x, y) (a, b) = (x+a, y+b) | ||
51 | shear c (x, y) = (c * x, c * y) | ||
52 | inside (p, q) (r, s) (a, b) = bet a (p, r) && bet b (q, s) | ||
53 | inside' (p, q) (r, s) (a, b) = bet' a (p, r) && bet' b (q, s) | ||
54 | |||
55 | -- [f, f.f, f.f.f, ...] | ||
56 | repeatF f = f : map (f .) (repeatF f) | ||
57 | |||
58 | makeGrid :: String -> (Map (Int, Int) Char, Int, Int) | ||
59 | makeGrid s = (grid, width, height) where | ||
60 | rows = lines s | ||
61 | grid = Map.fromList [((x, y), a) | (y, row) <- zip [0..] rows , (x, a) <- zip [0..] row] | ||
62 | width = length (head rows) | ||
63 | height = length rows | ||