From 6574f2fbe3ce537e01de813b4ac1d66f42dc78f6 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Thu, 3 Dec 2020 14:41:13 +0100 Subject: Day 3 --- 2020/3.hs | 25 +++++ 2020/3.in | 323 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2020/Makefile | 2 +- 3 files changed, 349 insertions(+), 1 deletion(-) create mode 100644 2020/3.hs create mode 100644 2020/3.in (limited to '2020') diff --git a/2020/3.hs b/2020/3.hs new file mode 100644 index 0000000..20fe0ec --- /dev/null +++ b/2020/3.hs @@ -0,0 +1,25 @@ +module Main where + +import qualified Data.Array as A + +import Input + + +main :: IO () +main = do + input <- getInput 3 + let height = length input + width = length (head input) + + let grid = A.array ((0, 0), (height - 1, width - 1)) + [((y, x), fromEnum (c == '#')) + | (y, row) <- zip [0..] input + , (x, c) <- zip [0..] row] + + countSlope hor ver = + let nsteps = height `div` ver + in sum [grid A.! (ver * i, hor * i `mod` width) | i <- [0..nsteps-1]] + + print (countSlope 3 1) + + print (product (map (uncurry countSlope) [(1,1), (3,1), (5,1), (7,1), (1,2)])) diff --git a/2020/3.in b/2020/3.in new file mode 100644 index 0000000..9ba5fa1 --- /dev/null +++ b/2020/3.in @@ -0,0 +1,323 @@ +.....#.##......#..##..........# +##.#.##..#............##....#.. +......###...#..............#.## +.....#..##.#..#......#.#.#..#.. +..#.......###..#..........#.#.. +..#..#.##.......##.....#....#.. +.##....##....##.###.....###..#. +..##....#...##..#....#.#.#..... +.....##..###.##...............# +#.....#..#....#.##...####..#... +#......#.#....#..#.##....#..#.# +##.#...#.#............#......#. +.#####.......#..#.#....#......# +..#.#....#.#.##...#.##...##.... +.....#.#...#..####.##..#....... +#....#...##.#.#.##.#..##.....#. +##.##...#....#...#......#..##.. +....##...#..#.#...#.#.#.....##. +..#....##......##....#.#....#.. +#..#....#....###..#.##....#.#.# +..#.#####..##....#....#.....##. +.#...##.......#...#....#.#...## +#.#.#.##.......#.....#.#.#....# +.#.#.....#.......#.......##.... +.#......#....#....#.......##... +#......#.....#......#..#..#.... +#.#...#...#....##....#.#...#..# +....#.....##...#...#..#.#...... +..#......#..........#...#.#.... +..#..#......####..##...###..... +.#.....#...##...#.##........### +#.#....#..#....#..#.....#.#..#. +...##.##.#.#.##...#.....#...... +##....#.#.#...####.#.#.#.#..... +.##.........#..#..###.......... +..##.###.#..#..#....##.....#... +##........#..###....#.#..#..#.. +....#.#.......##..#.#.#.#...... +....##.....#.........##.......# +..#........##.#.........###..## +....#..................##..#... +#...#.#..###..#.....#..#..#...# +..#..#.##..#..#.......#.......# +.....#..##..#....##...........# +..##...#........#...#.#.......# +.........#.#..#.#..#.##.#.###.. +....#...#..#..#......##....#.#. +..#..#.#....#....#..#.####..##. +##....#.....#......##.###.#..#. +#..#..##..###......#.#.#.#...#. +.......#..##..##...#...#..#.... +..#.###.#...#....#.##.#.....##. +.#.#.......##...##...##....#... +#...#.#.#...#.####..#..##...... +###..#.##..#..........#...#.... +##.#.........#..##......####... +..##.#..#....#.##.............. +...#....#.......###............ +...#.....##....#.#.#.#.......## +###.###...#...#...###.##...##.. +#.#....#.##..#.....#.....##.#.. +...#....#....#.........#....#.# +##.#....#........#..#..##.#.... +.#.#..#.......#...##.......#... +.##...##........#....#.#..#.... +....#..#.##.###.....#.#........ +.#.#...#.#..#.....#.........#.. +.......#.#.#..##....#.........# +.##...#....#..#...#........#..# +....#....#..#.#..#.#.#....##.## +..##....#.....##..#.#...#...#.. +#.##.........#.....#.......#.## +...#...##.#.#..........#......# +###...#.....#..#.......#####..# +#.####...##.#.#..#...#......... +.##.....#.....##..#...##.##.... +.........###...#......##....### +.#....##...###.#..#...##..#.#.# +.......#.......#.#...##.#...... +.....#.#........#..##.....##... +....#.#.........##.#...##..#.#. +#..#..#.##..#.##.##.....##.###. +..##.........###...#....#....#. +.###...#..#.##...........#..... +#..##..........#..........#.... +.....#.#....#..##..#...#.#....# +..#.....#.#....#...##.##....... +##.....##........#....#..##.... +.#..#.#.........#..#..#........ +.............##....#....#..#... +....##....#..#.#.##....###.##.# +.###..#.....#..#..##..#..##..#. +...#..###.......#.#....#..###.. +#.#..#.....#...#......#........ +#..#..............###.#......#. +..#....##.#....#.##.#.#...#.... +.........##..#...#.#.......#... +........#...#.#....#.....##..#. +...#.##..#..#..###..#..#......# +.....####......#...#....#...#.# +...###.#.#......#....#.......#. +#...##.#....#....##....##.###.. +.......##...##.....#.##.#..#..# +.....#.#............##...#.#### +.##..#.#.#.#..#.#.#.....#.##... +.#..####...#.#....#.....#..#... +....##..#.#...#..#....#.#...... +...#......###..#..###..#.....#. +.#.#.#..##....#...##..#.....#.. +###....#....#...##.....#...#... +#.##....#......#...###......... +.#..#.#...#..#....#....#....#.. +...............##...####..#..#. +#.#...........####..#...##..... +##.#....#........#......#...##. +......#...#...#....#....#.....# +#......#.............#....###.. +.#...#...##.....#...##.##..#... +..#.#......#.#........#........ +.......#..#.#...##..#.#.#...... +..##...#.##........#....#.#...# +.....#..#..#........#.#......## +....#.#...##............##....# +.#.#....#.#.#...#...#.##.....#. +#.#.##...#....#.#.#..#.##..#.#. +.........####..#...#...#....... +#..#..####......#..##..#...#... +.........##..................#. +.....##.#..##.#.#...#......##.. +...#....#....#.#.....#...#..#.# +#...##.#...##...........#..#... +#..........#.#..#..#.##..#..#.# +.#...#.##...#.#.#..#.......##.. +.........#...........#..#..#... +.##...##....#.#......#........# +#.#...........#....#.......#... +##.#.#.......#...###......##..# +...###..#.##..##.#.#.......#... +.#...#..##.#...#........#.....# +...#.......#..#..........#.#... +..#.#.#.#.....#.#.......#..#..# +#.##.....#..##...#..###.#....#. +.......#...........#...#....### +.......#..#...#.............#.. +#.....###.......#...#........#. +.#..#..#..#...........#........ +....#.#...#.#.##.#.#....#.##..# +.......#..##...##...#...#...... +...#.....##.###...#.#...##....# +#..#....#...##......#....##.... +#.#.......#....#.###.##..#..#.. +..##...........#...#....#...... +.#........#.....#..#..#...#..## +.....#.#.#..#.......#....#..... +#..#.#......#......##....#..... +##.....................##...... +.##........###..#.........#...# +........#.........#..#......... +.#.##....#.....#...#.........## +....##......#.........#........ +...#.#..#...##.##.#.#..####.... +..##...........##.#.#....#..... +.#.....#.#...#..#.......#....#. +....#...#......##...#...##.#..# +....#..##....#..#.........##.#. +..##...##.##....#....##.###...# +..#....##..##.#.#.#...#......#. +##...#.........#...........#... +.##....##.#.....#...#.......#.. +..........##.###.##....###....# +..........#..##..#....#.#.##.## +........##.#...#.#.#.#...###.#. +.#......#.#.#...###.#.#.#...... +.........#......#......#...#..# +......#.....#.##....##.#####..# +..#..##...###.#..........#.#.#. +.#..#....###.#...#..#....#...## +...................#..........# +....###.....#...##......#.....# +#.....#..##.....#.#..........#. +..#.......##.#....#..#.##.#...# +........##.#..###..#......##... +#...........##.#...###..#....#. +....#...........#.....#.#...#.. +.##..#.#...#...#.##...#..#..... +#........#.#.#.#.#.#........... +#..#.....#..#..#.##....#....#.# +..#............##....#.#.##...# +.....###.#....#.#......#.###... +...#.....#.#.................#. +..#...##..#.#...#...#...#.....# +.##.#........#..#....##..#..##. +.#..........#...#.#..#..#.#.... +#.......##.........#.##..#.#### +.#..............#.......##..... +#......#.##..........#..#...... +..##...#...#.#...#............# +.##.##..##..##........##.....#. +.....#..#.....##............... +.#..#...##...#...#.....#....... +#......#...#.......#..##.###.## +###..##......##......###....#.. +....#..........#...#.##.#.....# +.........#....#..#..#.#..##.... +.....#.....#...........#......# +.#.......#...#....##...#.##...# +..##.#..............#..#...#.#. +.#..####.#.........#....#....#. +..###.#...#..#......#.......### +.#.#..##...###...#...#.#...#.#. +...#..##..###.#..#.....#.##.... +#...###.#...##.....####.....#.. +.#.##...#..#.#..##.....#....... +...#.##.....##.....#....#...... +.#...##.....#..###..#.......... +..........#...#.....#....##.#.. +.......#...#...#...#........#.. +#....##..#...#..##.#.#.....#... +.#.#..............#..#....#.... +.####.#.#.###......#...#.#....# +.#...#...##.#...............#.# +...#.......##...#...#....##.... +#..........###.##..........##.# +.......#...#....#.#..#.#....#.. +....#.##.#...###..#..##.##..... +..#.#.#......#.#.......###..... +#..................#.##....#... +#.....#..#.#.#..#...#.........# +..#..#...#.#.##........#....... +#..#.#..#..........###...#.#... +.......#.##....#........##.#... +.####.#.#...#.#...##.##.....### +........#.#...#.#..##...##..... +....##.##......#.##.........#.. +.#..#...#.#...........#........ +.......#..........#....#...#... +..###.#.###..#..#.....#..##.... +.#..........#.......##...#..... +.#.....#...#........#...#.##..# +.#..#.......#..#.......#.#.#... +....#..##.#...##...#.#....#.... +.....#.........#..#..#....#.... +..#.#..##....#..#..##.#.#.....# +........#.#...###....#.#.#..... +.#.....#.......#..###.#........ +.......#...#.#...#...##........ +##.............#.#.....#.#..#.. +.#....#.......#.#.......#..##.. +#.....#........#..##..##....... +...........#.........###......# +....#.##...#.#...#...#....#..## +......#..##......#......#.##.#. +......##....####...###...#..... +#....#..........#.#.##.....#..# +....#.#...........#.#.#.#.#...# +....####.....##...#..##..#...#. +#....#.###..###.....#..###..... +..##.........#......#...##.#... +..#.....#.#...#.##.#...#..###.# +..#.##..##........#.......#.### +.....#..........#.....#....#... +.......##..##..###.......#####. +..###......#.#....###....##...# +#..##.....#..###...#.....##.##. +#..#..##.##.###.####.##.#...... +.#.#......#.##......#..#......# +..###.....#.#......#.#.####.... +#..............#..#.#...#.###.. +...#..#.##..........##.#...#.## +.#.#.#.........#....#.#..#..... +..#.##..#...#..#...#......#.... +.......#...#.##.#.#..#...##..#. +..........#.####...#........#.# +....#...#....##.#.........#.#.. +##.#..#.......###....#..#..#.#. +..##.....#..#.#.#.####......#.. +.#.....#..........#..#..#.#.... +......#.#.......#.#...#..#..#.. +...#...............#....#...#.. +##.......#.........#.......#... +...#.......###...#.#...#....... +#...###....#....##....#....#... +...#....##..#.#.............##. +.....#.#.#..#......#...#.#..#.. +.##....#..##..#####..##.....##. +....##.#.#..#.....#.#...#...... +...#.....##.#.#..##..#.#....... +.......#..#..#..........#...... +.......#...#..#.........#.##... +..#..#..#...##..#.#....#......# +..#....#...#.#......#........#. +.#...#..#...#.#..........#..... +#..#...####..#......##.##.#.#.. +.#...#.#...#.#.....#..##.#..... +..#.##.#......#.........##...#. +###..............#............. +...#...###....#..#............. +.##....#......#..#.....#..#..#. +.#..........#.....##...#..#.... +....##..#.#......###.##......#. +.#..##.#.##.#...##.#......###.# +#..###.#...###..#........#.#... +#..#.#.#..#...###.##.##..#..#.. +#.#..#....#.........##......#.. +....###.....###....#........... +....#..##.##....##..#.....#.... +.#.....#....####...#..##.#..### +.........##..#......#.#...##... +.##.......#.....#.###.#..#.#..# +.....#.#...###.....#......####. +##.#...#......#.#.#..#.####...# +.#.##.....#..#..#.............# +.#..###..#..#......#..##......# +.......#.#........##.....#.#... +#....#...#..###..#.#.....#.##.. +.##.....#.#....###..#.....##... +...##....#....#...#....#.#.#... +#####..#...........###....#...# +.#.......##.##.....#....#...... +.#..#.#...#..#......#...#..#.#. +....#.....##...#####..#...#...# +###.##...#.#............#....#. +.....#...#........##.........#. diff --git a/2020/Makefile b/2020/Makefile index b05b096..0b1c54f 100644 --- a/2020/Makefile +++ b/2020/Makefile @@ -1,5 +1,5 @@ GHC = ghc -GHCBASEFLAGS = -package parsec +GHCBASEFLAGS = -package parsec -package array GHCFLAGS = $(GHCBASEFLAGS) -Wall -O2 -threaded CXX = g++ CXXFLAGS = -Wall -Wextra -std=c++17 -O2 -- cgit v1.2.3-70-g09d2