diff options
Diffstat (limited to 'execs')
-rw-r--r-- | execs/Day02.hs | 4 | ||||
-rw-r--r-- | execs/Day03.hs | 18 |
2 files changed, 18 insertions, 4 deletions
diff --git a/execs/Day02.hs b/execs/Day02.hs index 87c90ec..f67778b 100644 --- a/execs/Day02.hs +++ b/execs/Day02.hs | |||
@@ -1,8 +1,5 @@ | |||
1 | module Main where | 1 | module Main where |
2 | 2 | ||
3 | import Data.Char | ||
4 | import Data.Either | ||
5 | import Control.Monad | ||
6 | import Text.ParserCombinators.Parsec | 3 | import Text.ParserCombinators.Parsec |
7 | import Text.Parsec.Char | 4 | import Text.Parsec.Char |
8 | 5 | ||
@@ -42,4 +39,3 @@ main :: IO () | |||
42 | main = do | 39 | main = do |
43 | n <- map (fromEnum . doCheck2 . parseLine parseProp) . lines <$> readFile "input/02" | 40 | n <- map (fromEnum . doCheck2 . parseLine parseProp) . lines <$> readFile "input/02" |
44 | print $ sum n | 41 | print $ sum n |
45 | |||
diff --git a/execs/Day03.hs b/execs/Day03.hs new file mode 100644 index 0000000..a000e59 --- /dev/null +++ b/execs/Day03.hs | |||
@@ -0,0 +1,18 @@ | |||
1 | module Main where | ||
2 | |||
3 | main :: IO () | ||
4 | main = do | ||
5 | n <- lines <$> readFile "input/03" | ||
6 | print $ countTrees 3 1 n | ||
7 | print $ product [ countTrees 1 1 n | ||
8 | , countTrees 3 1 n | ||
9 | , countTrees 5 1 n | ||
10 | , countTrees 7 1 n | ||
11 | , countTrees 1 2 n | ||
12 | ] | ||
13 | |||
14 | countTrees :: Int -> Int -> [String] -> Int | ||
15 | countTrees right down ls = go (map cycle ls) | ||
16 | where go [] = 0 | ||
17 | go remaining@(r:rs) = i (head r) + go (map (drop right) (drop down remaining)) | ||
18 | where i = fromEnum . (== '#') | ||