Compare commits
No commits in common. '40c5f7b10f4d4e819272fec95cc896f63a932cb3' and '0e125a1cb0986af4428e16ef433e1b7a55fc9a91' have entirely different histories.
40c5f7b10f
...
0e125a1cb0
4 changed files with 1 additions and 398 deletions
@ -1,323 +0,0 @@ |
||||
.##.#.........#.....#....#...#. |
||||
.#.#.#...#.......#............. |
||||
......#..#....#.#...###.......# |
||||
.......###......#.....#..##..#. |
||||
..#...##.......#.......###..... |
||||
....###.#....###......#....#..# |
||||
......#..#....#...##........... |
||||
..#..#....#...#.....####....... |
||||
...#........#.#.......#..#...#. |
||||
......#...#........#...#..##... |
||||
#..#........#............#...## |
||||
..#..#.#....#...........#...### |
||||
#.#..#...........#.##.#.#....#. |
||||
.#.#....#...##.....#........... |
||||
.....##....#...#..............# |
||||
...#....#...#.#.#.#...#........ |
||||
#....#....#.#.#..#....#..#..#.. |
||||
.................#..#.....#.... |
||||
#..###...#.#..#.#......#....... |
||||
...#..........#......#....#.... |
||||
.#.#.........##..#.......#...#. |
||||
.#..........#...#..#........... |
||||
....##.#....................... |
||||
.......#...........#...#....... |
||||
...#...#..##...#....###..#....# |
||||
....#.#.....##...##.#.#........ |
||||
...........#.#..#.#......#..#.. |
||||
.....#.....#....#...#........#. |
||||
..#......#..#.........#.....#.. |
||||
.........................#...#. |
||||
#...#...#....#........##....#.. |
||||
#..#.#.............#..........# |
||||
.#.........#.....#..#.#.#..#.#. |
||||
#...#..#.......####.#....##.... |
||||
##...##..#.#.#...#.#.....#..#.# |
||||
.#..#....#.##........#...#....# |
||||
#...#..##.#....##..#..#.#...... |
||||
.#........#.....#.#....##.##.#. |
||||
...#...#........#..#.##.##..... |
||||
....................#.#.#.#...# |
||||
..####.#..##...#....#.....##... |
||||
#......#.....#.#......#.#..#.## |
||||
..#.....#..#...........##.#.... |
||||
#....#........#............#... |
||||
..##....#..............#......# |
||||
..#......#.#.......####......#. |
||||
..............##....#....##.#.. |
||||
.#...............#....#....#.#. |
||||
..#.#.#..#.......##.#.......... |
||||
.#...#.......#.#....#.##....... |
||||
.....#.##...#...........#.#.... |
||||
..#.#..#...#..##...#.#.......## |
||||
.#.....#....#.#......#.#....... |
||||
....##.........#.#............. |
||||
.......##.......#.............. |
||||
..........#......#......#....## |
||||
..##.....#..#.#..........#..... |
||||
...#....#.......#....##........ |
||||
.......#...........#........... |
||||
...#.#......#.#........#....#.. |
||||
.....#...........#.#.#...#.#..# |
||||
.#.#...#.#.#..........#.....### |
||||
#........#...#................. |
||||
...##.....#.....#..#..#.......# |
||||
......##...........#..#....##.. |
||||
.........#............##...#... |
||||
.....#.....##...##............. |
||||
.#....#..#.#.#.#...#..#..#..... |
||||
.....#..#.#..#....#..#......... |
||||
....#.....#......#...#......... |
||||
#..#..#.................#...... |
||||
.###.....#...#.#........##.#... |
||||
..#...#....#.##..#.....#.#....# |
||||
..#...##.................#.#... |
||||
....##..........#..#..#..#....# |
||||
....#..##....##.....#.#....#... |
||||
.#.#.#.....##........#.##..##.# |
||||
....#..#......#..#........#.... |
||||
.......#.....###.#....#.......# |
||||
#....#.......#......##.#....... |
||||
.##.#.........#.#..##..#....##. |
||||
......#........#.#....#...#.... |
||||
.####.....#.........#.#......## |
||||
##....#......#....#..#.#....##. |
||||
...........###.#.....#..#...... |
||||
.......#...........#........... |
||||
........###....#..#.#.......... |
||||
....#........#......#.......... |
||||
.........#......#.............. |
||||
...#...............#......#...# |
||||
....#..##...#.........#...#.... |
||||
##........#.#....#......###.... |
||||
....#.......................#.. |
||||
#................#.#..#......## |
||||
...#.#.....#...#...........#.## |
||||
.#....#.##......#...##.#....#.. |
||||
#...#....#..............#..#..# |
||||
.......#....#.##............#.# |
||||
.....#.#.......#.#...#......... |
||||
...#.....#..##...##...#........ |
||||
..#.......#..####..#..#...#.... |
||||
#.#................##...##.#..# |
||||
.....#.....##.#.....#......#..# |
||||
....#.#...#.........#.........# |
||||
..#......#............#.....#.. |
||||
.....#..........#.#..#..##...## |
||||
........#................#.#... |
||||
#...#.#....##...###...#.#...... |
||||
.............##.#..##.......... |
||||
#..#......#...........#......#. |
||||
#.#....#..........#.##....###.. |
||||
.............#.........#....#.. |
||||
#........#..#.#..#...#....#.... |
||||
..............#..............## |
||||
.....#...#..............#.##... |
||||
#...##..#...........#.......... |
||||
..#....#...#.#........#..#.#..# |
||||
..##......#...............#.... |
||||
....#...#..###..#......###.#... |
||||
.......##..#.#........#....#... |
||||
..##...#.......#...#........... |
||||
.#.......#.....#.#...##..#....# |
||||
.............#.......#.#.#....# |
||||
#.......#..#..#...#.#......##.. |
||||
#.##..#..#..#....##.#...###.#.# |
||||
...##...#..#..#........#.#..#.. |
||||
#....##........................ |
||||
##...#...#......#.#.....#..#... |
||||
......#............#....#...... |
||||
#......#.......#.......##.#.... |
||||
..................#..#..#.#.... |
||||
..#..................##.#...... |
||||
..##........#.#.....##..#..#.#. |
||||
#....#..............#....####.. |
||||
#..#..........................# |
||||
..#.#.#.#....#.......#....#.#.. |
||||
.....#.#........#..........#.#. |
||||
........#.....#.......#........ |
||||
#.....#....#.###.....#.......#. |
||||
.....##.#...#.#..#...#.#.#..... |
||||
......##...#.#...##..........#. |
||||
.#............#.....#..#....#.. |
||||
.#................#.#..#....... |
||||
....................##...##.... |
||||
#.......##...#.....#..#........ |
||||
.##....#.#.#.#...........#...#. |
||||
..#.#..#.#.........#........... |
||||
...#......#.....#...##......... |
||||
..........#.#.....###.#........ |
||||
.............#.....##.......... |
||||
.........#...####........#.#### |
||||
...................#....#...... |
||||
.....#.........#.#....#..#...#. |
||||
.##...#.......##.#...#.#.#..#.. |
||||
.....##........#....#...#.##.#. |
||||
#...#...#.#....#..............# |
||||
#..#.##.............#.......... |
||||
..#...#..#.#.##..............## |
||||
#......#.#...##..........#.##.. |
||||
.##.#...#...#.........#.#...... |
||||
......#........##.#..#......... |
||||
#..#.......#......#.#..#.#..... |
||||
.#..#...........#.#.##.....#... |
||||
.....................#..#.#.... |
||||
........#...##......#.....##... |
||||
#.............#...##....##....# |
||||
#.#...........#....##.#......## |
||||
.....#.....#.#..........###..#. |
||||
....#...#....##....#..##....... |
||||
.#....#....#.......#.#.....#... |
||||
.#...#.......##...##........#.. |
||||
......##.......#.##.#.###...... |
||||
....##.......#......#.......... |
||||
...................#..##....... |
||||
......................#...##... |
||||
...##....#.#..#..#............. |
||||
.#......##..........#...#...... |
||||
....##..#....#..#...#...####.#. |
||||
...#.......#.......#........#.# |
||||
#.........#..#...#...##...#.#.# |
||||
....#...#.......#...#....#..... |
||||
...#.....#.##..##.#.......##.## |
||||
.......#....#........#......... |
||||
.....#...#....#..#....#....#... |
||||
.##....#...#........#...#.#...# |
||||
.......##............#..#...#.. |
||||
#.#...#....#......#.#.......... |
||||
.#.##...........#........#..... |
||||
.#....#.............#.#.##..... |
||||
#.......###..#...###.........#. |
||||
#..#.#.......#.........#...#..# |
||||
..........#......#........#...# |
||||
.#.#...#.##.......##........... |
||||
.....#.........#.....#......... |
||||
.........#.........#....##.#..# |
||||
.#.......##..##..#.....#...#... |
||||
.#.....##...#..#..............# |
||||
..##...#..#..#.#...#..........# |
||||
.#.......####......#......####. |
||||
##..##........#.....#........#. |
||||
..##.#..#.#.................... |
||||
...........#..#...##....##..... |
||||
..#.#........#.........#....##. |
||||
..#...#..##..###.#..###........ |
||||
......#..#.............#..##... |
||||
.##.........#.#..#...#.##.###.. |
||||
.#...............#...........#. |
||||
.#....#........#....#........## |
||||
..#####.#.#..#.#........##...#. |
||||
###....#....#...#.............. |
||||
.....#...##............#...#... |
||||
##...........##.#.##.....#..... |
||||
..............#..#.....#...#... |
||||
...................#........... |
||||
#..........##.........#........ |
||||
...#.........#..#.....#..#..#.. |
||||
....###.#......#......##....#.. |
||||
#......#..........#...#........ |
||||
...#.#...#..#..........##...... |
||||
.....##.....#.#............##.. |
||||
..#..#.###....#.#.#...##....#.. |
||||
...#........#....##.......#.... |
||||
.#.............#..##.......#... |
||||
..#.#..###..#.....#...##....... |
||||
.........#......##...#.#..#.... |
||||
.............#....##....#.#.... |
||||
#..#...#....#.#...#......##.... |
||||
.............#.#......#.....### |
||||
#.##....#........#............. |
||||
.....#...#.####...#.....#...... |
||||
....#....###....##.......#..... |
||||
..#....##..#....#.#.......#.... |
||||
...#.....#....#.........#...... |
||||
.#......#.#....#.#........#.... |
||||
.......#......#.....#.#..#..... |
||||
#......#.........##.##.#...#... |
||||
..#.###...................#.... |
||||
....#..#....##.#........#....#. |
||||
...........#..........#......#. |
||||
.#..#.#...###..........#..#...# |
||||
...#...##..#....#...#.......... |
||||
.#........#.................##. |
||||
....#.......##....#...#........ |
||||
#.#...##.##...#.#.......#...#.. |
||||
.....#.#.##.#......#..#..##.... |
||||
.....##...#.#.....#...#........ |
||||
#.#.......#..#..........##..... |
||||
................#......#..#.#.# |
||||
#......#...#................... |
||||
...#.....##.#.........#.#..#..# |
||||
...#..##..##.......#....#...... |
||||
....##...#....#..#...........#. |
||||
..#..#......#...#..#........... |
||||
...#.##....#...##.......#...... |
||||
.......#....#..#..##..#..#....# |
||||
.#.................#.#...#.##.. |
||||
.....#..................#..#.#. |
||||
...#......##...#...........#... |
||||
..#.........#....#..#...#.....# |
||||
..#...#.....#.........##.#..... |
||||
.....#.#....##...............#. |
||||
....#...#............#......... |
||||
.....#.....###............#.... |
||||
..#.#.#.......#....#........... |
||||
...........##...##...#.......#. |
||||
.........###.#......#.......... |
||||
.#.......#....#.....#.##..#...# |
||||
..#..................#..###.... |
||||
..#....#...#......##.........#. |
||||
........#..#........#.........# |
||||
.#..#......#.........#......... |
||||
...#..##.....#....#....#.....#. |
||||
......#.#............###.....## |
||||
.......#........#.......#.#.... |
||||
..#.............#.............. |
||||
.............##..#.#.#....#.... |
||||
.................#....#.#...... |
||||
##..#.#.......#....#.....#..... |
||||
.##............##.#.......#.#.. |
||||
#..#...........##......#....... |
||||
.##......#####..##.#....#.#.... |
||||
.......##.....#...#........#... |
||||
.#.#.....##....#..#....#..#...# |
||||
............##.#.....##.#...... |
||||
........##...###.#......#...... |
||||
......#..#.#...#..#............ |
||||
.........#...........#......#.. |
||||
.#.........#............##..... |
||||
.#..#..#...#.#.............#... |
||||
......#.#..##...#.#...........# |
||||
#.##.......#...#.........#..... |
||||
.....#..#............#....##... |
||||
.#......#........#............. |
||||
..#...#....#..#.......###...... |
||||
....#.......###.#.#...........# |
||||
.............#...##............ |
||||
.##.#.#.#...........#...#....#. |
||||
............##.........#......# |
||||
...............#......#...#.... |
||||
...#.....#..###..#...........#. |
||||
.#........#.....##........#.#.. |
||||
....#.#.......#..#..#...##.#.#. |
||||
.......##...........#...#...... |
||||
....#.#..##......#.......#..... |
||||
..#........#.#......#.#........ |
||||
........#....#..#....#..##..... |
||||
.#.........##..........#.#..... |
||||
..##...##.....##......##..#.... |
||||
.###.....##...........##.#...## |
||||
...#................#.......#.. |
||||
#.......#.#.#..#.#.##..#...#... |
||||
.#.#.......#..#................ |
||||
..#.#.#......#............#.... |
||||
#.....#.###..#.#...#........... |
||||
#...........#..........#.#.#.## |
||||
..#.#...#......##.....#........ |
||||
........#.......#.#...#...#.... |
||||
..#..........#......###......#. |
||||
..........##.#....#.....#.##... |
||||
..#.....#......#.........#..##. |
||||
.#...#........#..#.#..#...##..# |
||||
..###........#......#.#........ |
||||
..#.##.#....#.#....#.#...#..... |
@ -1,71 +0,0 @@ |
||||
{-# LANGUAGE DataKinds #-} |
||||
{-# LANGUAGE OverloadedStrings #-} |
||||
|
||||
module Day3 (day3) where |
||||
|
||||
import Control.Applicative ((<|>)) |
||||
import qualified Data.Attoparsec.Text as P |
||||
import qualified Data.Text as T |
||||
import qualified Data.Vector as V |
||||
import Numeric.Natural (Natural) |
||||
|
||||
data Loc = Tree | Open deriving (Show, Eq) |
||||
|
||||
type Hor = V.Vector Loc |
||||
|
||||
type Grid = V.Vector Hor |
||||
|
||||
parserLoc :: P.Parser Loc |
||||
parserLoc = do |
||||
loc <- P.char '.' <|> P.char '#' |
||||
case loc of |
||||
'.' -> return Open |
||||
'#' -> return Tree |
||||
|
||||
parserLine :: P.Parser Hor |
||||
parserLine = do |
||||
locs <- P.many1 parserLoc |
||||
return $ V.fromList locs |
||||
|
||||
parserGrid :: P.Parser Grid |
||||
parserGrid = do |
||||
grid <- parserLine `P.sepBy` P.endOfLine |
||||
return $ V.fromList grid |
||||
|
||||
slideDown :: |
||||
(Natural, Natural) -> |
||||
(Natural, Natural) -> |
||||
Grid -> |
||||
Maybe [Loc] -> |
||||
Maybe [Loc] |
||||
slideDown _ _ _ Nothing = Nothing |
||||
slideDown (x, y) (x'inc, y'inc) g (Just r) |
||||
| y >= (fromIntegral . length) g = Just r |
||||
| otherwise = do |
||||
hor <- g V.!? fromIntegral y |
||||
let x' = x `mod` (fromIntegral . length) hor |
||||
loc <- hor V.!? fromIntegral x' |
||||
slideDown (x' + x'inc, y + y'inc) (x'inc, y'inc) g (Just (r ++ [loc])) |
||||
|
||||
countTrees :: [Loc] -> Int |
||||
countTrees = length . filter (== Tree) |
||||
|
||||
parseGrid :: String -> Grid |
||||
parseGrid s = |
||||
case P.parseOnly parserGrid (T.pack s) of |
||||
Left s -> error (show s) |
||||
Right r -> r |
||||
|
||||
day3 :: IO () |
||||
day3 = do |
||||
r <- readFile "./input/day3" |
||||
let grid = parseGrid r |
||||
putStr "[Day 3-1] # trees: " |
||||
case slideDown (0, 0) (3, 1) grid (Just []) of |
||||
Nothing -> putStrLn "ERROR" |
||||
Just locs -> print . countTrees $ locs |
||||
putStr "[Day 3-2] # trees: " |
||||
let mTrees = mapM (\x -> slideDown (0, 0) x grid (Just [])) [(1, 1), (3, 1), (5, 1), (7, 1), (1, 2)] |
||||
case mTrees of |
||||
Nothing -> putStrLn "ERROR" |
||||
Just trees -> print . product $ map countTrees trees |
Loading…
Reference in new issue