aboutsummaryrefslogtreecommitdiff
path: root/execs
diff options
context:
space:
mode:
Diffstat (limited to 'execs')
-rw-r--r--execs/Day02.hs4
-rw-r--r--execs/Day03.hs18
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 @@
1module Main where 1module Main where
2 2
3import Data.Char
4import Data.Either
5import Control.Monad
6import Text.ParserCombinators.Parsec 3import Text.ParserCombinators.Parsec
7import Text.Parsec.Char 4import Text.Parsec.Char
8 5
@@ -42,4 +39,3 @@ main :: IO ()
42main = do 39main = 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 @@
1module Main where
2
3main :: IO ()
4main = 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
14countTrees :: Int -> Int -> [String] -> Int
15countTrees 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 . (== '#')