From 6bd6cf1350e96011c08652cdbb1dd39279666715 Mon Sep 17 00:00:00 2001 From: Akshay Date: Thu, 3 Dec 2020 11:23:13 +0530 Subject: add initial day 3 solution --- aoc.cabal | 6 ++ execs/Day02.hs | 4 - execs/Day03.hs | 18 ++++ input/03 | 323 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 347 insertions(+), 4 deletions(-) create mode 100644 execs/Day03.hs create mode 100644 input/03 diff --git a/aoc.cabal b/aoc.cabal index 6dbd463..e88e933 100644 --- a/aoc.cabal +++ b/aoc.cabal @@ -27,3 +27,9 @@ executable Day02 build-depends: base, parsec default-language: Haskell2010 hs-source-dirs: execs + +executable Day03 + main-is: Day03.hs + build-depends: base, parsec + default-language: Haskell2010 + hs-source-dirs: execs 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 @@ module Main where -import Data.Char -import Data.Either -import Control.Monad import Text.ParserCombinators.Parsec import Text.Parsec.Char @@ -42,4 +39,3 @@ main :: IO () main = do n <- map (fromEnum . doCheck2 . parseLine parseProp) . lines <$> readFile "input/02" print $ sum n - 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 @@ +module Main where + +main :: IO () +main = do + n <- lines <$> readFile "input/03" + print $ countTrees 3 1 n + print $ product [ countTrees 1 1 n + , countTrees 3 1 n + , countTrees 5 1 n + , countTrees 7 1 n + , countTrees 1 2 n + ] + +countTrees :: Int -> Int -> [String] -> Int +countTrees right down ls = go (map cycle ls) + where go [] = 0 + go remaining@(r:rs) = i (head r) + go (map (drop right) (drop down remaining)) + where i = fromEnum . (== '#') diff --git a/input/03 b/input/03 new file mode 100644 index 0000000..534b00b --- /dev/null +++ b/input/03 @@ -0,0 +1,323 @@ +.............#...#....#.....##. +.#...##.........#.#.........#.# +.....##......#.......#......... +.......#...........#.#......... +#...........#...#..#.#......#.. +.........##....#.#...#......... +.....#.........#.#...........#. +....#...............##....##... +#.#.............#..#.......#.#. +...#........................... +......#..#....#.............#.. +........#......#.......#....... +....#.....#..#.#...#.........#. +..#.#.......#.##...#....#.....# +...........#.........#..#...... +#...........#.#..#...#.#.#....# +........#...................... +....#.#.....#....#.......#..#.. +.............................#. +....##..........#.....##......# +......#.....................#.. +..#.....##.......#............. +....#.#..............#.#....... +..#.#........#.....#..##....... +.....#...##.........##....#.#.. +.#....#..#..#...........#...... +.............#.....##........#. +..#....#............#.........# +###..........#........#.......# +#...#..#.#.#.........#..#...... +..#....#......#.............#.. +#...#........#..#...#.....#.... +.#..........#.#........#....... +#.....#.........#..#......#.... +....#....##........#......#.... +.......#....#.....#..#..#.....# +.........#...#.#...#.##........ +.##.##...........#..##..#...... +.#.##....#........#...#........ +.......##.........##.####.....# +....#..##....#................. +.#........#..........#......... +##....##..........##........#.. +#......#...........#....#..#... +.......#..#....##..##.....#.... +.........#.#.#...#.....#....... +......#...#...#....#......#.... +##....#..........#....##....##. +###.........#...#...#.......... +#.....##.#........#.......#.... +#...............#...##.#......# +..#.....####.###......#......#. +....#.......#..........#....... +....##..............#.#.#...... +.......##..#.......#........... +..#.......##....#.......###...# +........#...#.......#.#...#.... +.........##....#..#....#....... +............#.#.......#.#...... +.....#.....#...#....#.##....... +.......#.........#.......#..... +.#..#...#.....#............#.## +.......#.#......##............. +##.#......#.....#.#............ +.#....#.....#............#...#. +.........#.......#.#........... +#............#.##...#..#...#.#. +......#....#.......#....#...... +..........#........#..#.#...... +#..##.......#.........#..#..... +.........#.....##........#.#..# +..#................#........... +....#..#........##.........#..# +###...#....##.#......##.......# +.......#......##..#.......#.... +.......###...#...#..........##. +................#.......#...... +.#......##.##........#......... +....##.#.....##.......#........ +...........#...........#.....#. +..#........#..#.#...#.#........ +#...............#...#.##.##.#.# +................#.......#...... +.#..#......#........#.#........ +...##..#.......#.......#..#.... +.#.....#.#....##..#........#... +........##......#..........#... +.#.......#.......#...#..#...... +.#..##.....#....#............#. +...#..........#....#........#.. +..#.#..#.......#.#.##.......... +#........###.....#.#.......#.## +.....#....##.............#.#..# +..##............#...##......... +...#.........#...........#..... +...#......#.#...#..###......... +.............#...##............ +.....##..##.####.#..#......#.#. +.#...#.....#.....#.#.....#..... +.........#.......###.....#..##. +.##.#..#..........#.##.#.#..... +.#...#...#.#.##......#..#...... +.............#......#......#... +#.....................#......#. +...#.....#.....#....#........#. +................##..#....#..#.. +#.###...#.....................# +...#..#....#.......#.........#. +...........#..#..#...........#. +.......#..#......#....#.#...... +..........#......#..#....#..... +.#.#.....#...#.#...#...#.#....# +.....#.......#............#...# +#.#....#......#......#........# +.#.#..#.........##...#......... +#..###..#...................... +..#.#..#....................... +.##.....#...#......#..#........ +...#...........#...#.......##.. +..#...........#........#....... +........#....#.....#.#......... +..........#...........#.....#.. +......#...#...##.#............. +.#...#...##.................... +............###.........#...... +.#.#...................#..#.... +....#.#...#.#........#.#....... +....#...#...........#.......#.# +...........#............#...##. +.....####....#.#......#.#...... +.##.............#............#. +......#.........#............## +#.#....#...##....#.......#....# +.....#.#....#..#..#...#..#.#..# +.........................#..... +......#.#....###.......#....#.. +.....................##.#...#.# +..#.....#.#.#...#...#.......... +........#..##........#...#...#. +..........#.#.##....#....##.... +.............#..#.............. +..#.##..#.......#...#..#..##..# +..#..#....#.#..........#..#.... +..........#....#...#......#.... +.##...#.......................# +.#.....#....#..........#....... +...........#..#......##.....#.. +......###.#..##....#...#.##.... +.......#..#.#....#............. +...#..#......##.........###.#.. +...........#............##...#. +...#...#...........##.....#.... +..................#............ +.#.#.#...#..............#..##.. +#.#....#........#.........#.##. +#.#.#.......#.....#..........#. +...##.....##.#.....#........... +.#....#..............##...##..# +........##..................... +#..#..#.....###.............#.. +.......#...........#........... +.........#..................... +.......#...#...#.....##........ +......#.........#........#..... +...#....##..#.####.#.......#.#. +.....#..#......#........#.##..# +.##....#......##......#...###.. +..###.#........##.#...#.......# +............#......##....#.#... +.....#....##..##............##. +......##....#.#...#....#.#..#.# +.......#.........#.#.....#.#... +.......#.#....#................ +.##...###..#.....#............# +#.#......#.#..#..#.#...#..#..#. +..#.#.#.....#............#...## +.##....###.........#..#........ +.#..#.#..#.#....#.........##.#. +....#..#...##.##........#...... +........#.#....##....#....#.... +.......#..#..#.#..............# +#....#....#.....#....#......... +.#.###...#....#.......#........ +.........#.#....##....#...#.... +....#.............#.....##.##.. +.....#.....#...##..#.#.##...##. +.........#..#................## +...##..##......#.....#........# +.#....#.....#.#......#..###.... +#.....#..#..................... +....#.#...#.#.................# +.....##..................#..... +#....##...#.##..###...#........ +##.#.........#.......#....#.... +.#.#.............##..#.##...... +...#.#..............#......#... +.............#.........#.....#. +#.......#........#......#.....# +.....#..............#.##.#..... +#......##...................#.. +##.#.....#..........#........#. +#...........##...........#..... +.#...#.....#..#..##....#....... +.....#.........#....##.#....... +#........#......#.............# +.#..................####.#..... +#...#......#....##...#.#..#..#. +............#.#............#... +............#........#.#..###.. +.#..#..#..#.#.#.....#.#........ +#.....#..#.#...#..#..#........# +#................#....#..#..... +....#..#..#.#......#.#..#.....# +.#..#.......#...##.#.#.....#..# +#.....................#.......# +.............#.......#...#..... +....#......#.........###.##.... +....#..#.......#.#........#.... +....#...#....#.#....#.......... +...#..#......#.............#... +.......###.#.........#....#.#.. +..#.....##..................... +.#.#...........#..##....#...... +..........##.#....#.#.......... +...........#.#..#.#..#.#....... +..........#..#...#.....##...... +.....#.........#...#.#..#...... +#.#................#..........# +...#.....##.#..#...#.##.......# +.....##...........#............ +.....#...#...#...#.#.....#..... +...........##.................. +.........#................#.... +......#.....#.#...#.......#.... +...#...#........#...#...#.#.#.. +...............##..#....##...#. +...#.#...........##.......##..# +...........#............#...... +.#....#.#.......##.#.#.#....... +.....#.#..#.#.#................ +.#............#...#.#.......... +.....#.......#.#.......#.....#. +#....#...........#...#....##... +..#...#..##.....#....#..#...... +#.#.........#..#.#..#.#......#. +................#......##...... +#........#..............#....#. +........#..#.#........#..#..#.. +#..........#......#............ +..##.......#..#.......#....#... +.#........#..#..#.#.......##... +................#.............. +#.................#...........# +##..#...................#....## +#..#....#.....#.#..#.#.#......# +#................#.#.#...#..... +.............#..#...#..##...#.# +#..................#........... +..............#..#.....##.....# +..#...............#.#.......... +.....#......#....#..#...#...... +.#......#...##.....###.....#... +...##...##.##....#.#.#..#...... +....#.#.......#..##....#.##.... +...#.........#.#.....#...#...## +.##.#.........##..#.##..#...... +.#...#......#......#.........#. +.............#................. +..........#..............#..... +##...........#...#...###....#.. +....#...............#.......... +.......####.....#......#....... +........#..........#..#........ +..#.......#..#................. +......#.#..##...##....#........ +.##...#........#...#....#...#.. +.......................#....... +.........##..#..#...#....##...# +..#..#...#.....#.........#..#.. +.......#....#.........#...#..#. +.............#................. +.....##..#.....###....##.#..... +....#.#..#..#.#.....##....#..#. +......#..#..............#.##..# +..#..#......#.#.........#..#... +..........#.#..#....#.....#.... +.....................#......... +...#.....#.......##..#.#....... +.....#...#..........###....#.#. +......#.....##............#...# +.......#..........#.#..#...#..# +#...#..#...........#..##..#.... +.#......#.......##.....#..#.... +...#..#....#.......##......#... +........#.......##...#.......#. +.....#........#................ +......#........#....#.......... +...#....#....###.........#.#... +##..............#......#..#.#.. +.........##....#........#..#.#. +.......#.##.#........#........# +.....###..#..#...........#....# +.......#....##.......#.#...#... +#..............#.#....#..#...#. +#..#....#..#.#............#..#. +.#...##.#..................#... +...#...............##.........# +###..............#.#..#.#.#.... +.#......#.#.....##.......#..... +...#.................#.#....... +.#...#....#...#..#......#...#.. +...##....#........#.#.#..#..... +..#.....#........#....#.#...... +...........#.#...#............. +......#.....#.....#.........#.. +.#.##.###...#.##.......#....... +.............#....#.......#.... +..............#...........#.... +.............#..#.#.....#....#. +.......#........##...##..##.... +..##...#............#..#......# +.............#...##.....#...... +.#...##..##.#.........#.##...#. -- cgit v1.2.3