Day 3
This commit is contained in:
parent
b992e83d76
commit
c02d76732b
23
2020/day03/day03.hs
Normal file
23
2020/day03/day03.hs
Normal file
@ -0,0 +1,23 @@
|
||||
main :: IO ()
|
||||
main = do
|
||||
input <- map (concat . repeat) . lines <$> readFile "input"
|
||||
print $ day3 input ((3,1),0)
|
||||
let slopes = [((1,1),0),((3,1),0),((5,1),0),((7,1),0),((1,2),0)]
|
||||
print $ product $ map (day3 input) slopes
|
||||
|
||||
type Slope = ((Int, Int), Int)
|
||||
|
||||
day3 :: [String] -> Slope -> Int
|
||||
day3 input slope = a
|
||||
where
|
||||
(_, a) = day3rec (input, 0) slope
|
||||
|
||||
day3rec :: ([String], Int) -> Slope -> ([String], Int)
|
||||
day3rec (t:ts, acc) ((x, y), l) =
|
||||
day3rec
|
||||
( drop y (t : ts)
|
||||
, if t !! (l * x) == '.'
|
||||
then acc
|
||||
else succ acc)
|
||||
((x, y), succ l)
|
||||
day3rec x _ = x
|
323
2020/day03/input
Normal file
323
2020/day03/input
Normal file
@ -0,0 +1,323 @@
|
||||
.#..#....##...#....#.....#.#...
|
||||
........##....#..#..##....#.#..
|
||||
......##......##.........#....#
|
||||
...#.....#....##.......#.#....#
|
||||
.#.###.#.#..#.....##..#....#.#.
|
||||
##.........##.....####......#..
|
||||
#...#..........#.##............
|
||||
####............#..........#.#.
|
||||
......#......#....##...#..##...
|
||||
#..#....#...#......#......####.
|
||||
......#..........#.........#.#.
|
||||
...##.......#..#.#..#..#....#..
|
||||
..####....#.#...............##.
|
||||
...###........#.....#..........
|
||||
#..#.##...##.#..##...##...#....
|
||||
.###........#.##..#.#.....#....
|
||||
.#.......#..##.......#......#..
|
||||
.##...........#..............#.
|
||||
...#..#.....#...........#...#..
|
||||
.....#..............#..#.......
|
||||
.......#....#.....##...........
|
||||
.#...#.............#.....##....
|
||||
....#.#....#...#...#..#..##.#..
|
||||
...#..##..##...#..##........#.#
|
||||
.###..#...#.#.#.#..#...#.......
|
||||
.....##.#.##.#.#.......#..#....
|
||||
.##.#...#.....#...#....#.....#.
|
||||
.....#......###....###..##.#..#
|
||||
.....#..##....#..#.#..#.#.#....
|
||||
#....#.....#.#.......#...#....#
|
||||
...#........#............#..#..
|
||||
#.#...#...#..##.........#...##.
|
||||
.#..#.#...........#....#...#...
|
||||
##..#.#..........#.....###...#.
|
||||
#..#........#.......#.#..#....#
|
||||
..#...##....#..#....#....#.....
|
||||
...#.....##....#...#..#....##.#
|
||||
.....#......#...#.#.#.#.#......
|
||||
###.....#..#.#..........##.#...
|
||||
...............#..#...#.#....#.
|
||||
#.....#.....###....#..........#
|
||||
........#...#.#.......#..#...#.
|
||||
..#.##...#...#...#.........#...
|
||||
#..........#..#.#...........##.
|
||||
##.......#.#.#...#.....#.......
|
||||
...#.#.#.....#......#....##..#.
|
||||
##.#.....#....#...#.......#....
|
||||
.#......##..#.##.#....##..##.#.
|
||||
..#..#......#....#...#..#.#....
|
||||
...#..###...#.......#..#.......
|
||||
...#....#..#....#........##....
|
||||
#...#...#....#.#.........###.#.
|
||||
.#.........##..##...#..........
|
||||
...##.....##.........#..#..#...
|
||||
###....#......#.##..#...#......
|
||||
.###....#.#.......#..#....#...#
|
||||
....####........##....#.#....##
|
||||
..#.....#......##...#..#..#....
|
||||
...#....#...#......#.###.#.#.#.
|
||||
......#.......#..#...#...#.....
|
||||
.#...#...#..#.#..........#.....
|
||||
........#..#.........#.#....##.
|
||||
.#....#.......#........#.##.#..
|
||||
...#...#..#.....#......#...##..
|
||||
.#.................#........###
|
||||
.......#.#..#.#...#............
|
||||
.#.......#..##...#.###....#.##.
|
||||
#........#.###.#..#........##..
|
||||
..##.#....##......##........#..
|
||||
...............#...............
|
||||
#.......#......##..#.#....#.#.#
|
||||
..#.....#......#.#.#...#...##..
|
||||
..........#........#.....##...#
|
||||
#..........#.#..#..##..#......#
|
||||
.......#..###..##.#..##........
|
||||
#.#..##..###..#.###.....#.#..##
|
||||
..#.#........#...###...##......
|
||||
.......##.....##...#.##........
|
||||
.#.#...###..#..#......##....##.
|
||||
#...#.#.....##..#..#..#.#....#.
|
||||
........#......#....#..#.......
|
||||
...#.#.#.#........###....#...#.
|
||||
.#......#...#.......#......#...
|
||||
#...#.##.#..#.#..#.........#...
|
||||
....#......##......#........#.#
|
||||
..##.#.....#..#......#..#......
|
||||
#.##...##...#................#.
|
||||
.....#..#....#....#####........
|
||||
....#..#..#.#...#.#............
|
||||
.........#.#....#..#....##...#.
|
||||
#....#..........#......#......#
|
||||
.......#..............#......#.
|
||||
.#..#...#..#.#.....#.#.#.##.#..
|
||||
.##........#......#...#.##.....
|
||||
...#.##..#........#...........#
|
||||
..#...#..#........#.......#.#..
|
||||
#.....#..#.#..#..#...#...#..#..
|
||||
..................#.#.....#...#
|
||||
........#...##.#..#.........#..
|
||||
.#...##.#...........##.##...#..
|
||||
#......#.........#...#...#...#.
|
||||
..........#.............#...#..
|
||||
#............##.#..#...#.#...#.
|
||||
..#.##...##....##.#...####...#.
|
||||
#.##..#......#.......#.#...##..
|
||||
.....#...#..#......#####.##..#.
|
||||
#...#.#.##..#..##.....#......#.
|
||||
.#..#......#.#.#...#.#...##.#..
|
||||
.#.....#..##........#.....#...#
|
||||
.................#..........#..
|
||||
##.#.#......#.####..#.....#....
|
||||
.#...##.####..#...#............
|
||||
..#...............###....#....#
|
||||
#...#..###..#.#.##...........##
|
||||
...................#..#.....#..
|
||||
...#.##.#...#.....#......#.##..
|
||||
#.#...#.........##.#........#.#
|
||||
.##.......#..#..#.....##....#..
|
||||
......##.#.#..#...#.#..##.....#
|
||||
..#..###...#...#......#.#......
|
||||
..##....#.#...#....#....#..#..#
|
||||
#..##....#........#..##..#..#.#
|
||||
.......#............#....##..#.
|
||||
.#.#..#.........#.#.##......#..
|
||||
#.#....#..##..#..###.#.....##..
|
||||
.###.#......#.....#####...#....
|
||||
#...#.#...##......#...#.#...##.
|
||||
#..#.........#..#............#.
|
||||
...##......##.......##....##...
|
||||
...#...##....###..###.#...#....
|
||||
#.#....#...#.#...##..#........#
|
||||
.#..#..................#....#..
|
||||
#......#..#...##..##...#..##..#
|
||||
...#..#.....#...#........#.#.#.
|
||||
#...#..##....#.....#........#..
|
||||
.##..#....#.....#.#............
|
||||
##..##.#.#.##.#.#..#.#..#....#.
|
||||
#.......#...............#.....#
|
||||
..#.....#..##.....#...##.##....
|
||||
...#..#...#.#.#....#......#....
|
||||
###.#.......#....#....#.#...#..
|
||||
.....###..#...###.#.#..#.......
|
||||
.....#.........##.#....#..##.#.
|
||||
........#....#....#....#.#..##.
|
||||
........###....#.#.........#.#.
|
||||
.#..###..#........#.......##.#.
|
||||
.#.#...........................
|
||||
..#....##...#.#....#....#.#....
|
||||
.#...#...##.#........###....#..
|
||||
#.#....#...#.#.#...##......##..
|
||||
#......#....#...#..#....#...#..
|
||||
...#..##........#.#...##......#
|
||||
....##...........##...#..#..#..
|
||||
......#..#........#..#....##.##
|
||||
.###..#.#.........#.....#......
|
||||
.#..##............#......#.....
|
||||
..##.#.#..#..#.###....#..#..#..
|
||||
....#.#..#.#..##...##.#.#.#.#..
|
||||
....#..#....#...............#..
|
||||
..#...#.##.....##....#..##..#..
|
||||
.......##.#....#.##....#.......
|
||||
.#...#........#...#......#.###.
|
||||
..#....##.......#....#.#...#.#.
|
||||
.....#.....#...##..#....#.#..##
|
||||
..##........##............##...
|
||||
..........#...#.......#.......#
|
||||
.#...............#...#.##......
|
||||
#.##......#....#.##.#..#..#...#
|
||||
......###.........#...#..#....#
|
||||
....#......#...#....#....#...#.
|
||||
#...##...#....#......####....#.
|
||||
.................#......#......
|
||||
..#..........##.......##..#.##.
|
||||
.#.....#.......#...######..#..#
|
||||
....##.#...#...#..........#....
|
||||
.....#.......#...#.#.......###.
|
||||
#...#.###.....#...#.......#....
|
||||
.#.##.####....#.....#.#........
|
||||
.......#.....##............##..
|
||||
..#...#.#.##........#...##...#.
|
||||
........#...####.##..#....#...#
|
||||
#.......#...##.#......#..#...#.
|
||||
......#.........#..###.#.#....#
|
||||
#..##...#...#..#...#...#.....#.
|
||||
.#...#...#.#.................##
|
||||
#......#.....#..#.#..#......##.
|
||||
.......#.##...#.......#.......#
|
||||
.#.#..#..#......#....#.#...#.#.
|
||||
..#...#.#..#......#...#.#.#....
|
||||
........#..............#..##...
|
||||
.##..#..##.#....#.#..###..#..#.
|
||||
..#....#......#...#.#.#....#...
|
||||
...#..#..#....#..#.....##......
|
||||
.#......#...#........##........
|
||||
.#......#..#...##..#..#.#.#....
|
||||
.##......#.##.........#....#...
|
||||
....#....##..#..###.#..#......#
|
||||
....#....##..........#.#...#...
|
||||
..##.#.............#..#.....#..
|
||||
..#.....#....#....#.......##...
|
||||
.##.#....#....#...#....##.#....
|
||||
...#.#..#.###.#..#.#.......#.#.
|
||||
.....##.....#.......#......#...
|
||||
.#.....#..#.#.#..#........##...
|
||||
##.....................#.......
|
||||
..###............#........##..#
|
||||
.#.##.....#..#..#..#.#.......#.
|
||||
.##...................#..#..#..
|
||||
..#.#...#..........##..#..##...
|
||||
#......#..#..#.#..#......#..#.#
|
||||
.#...#....#.#.........#.....#.#
|
||||
#..........#.#....#....#.#.#.#.
|
||||
#.....#..........#..#....#..#..
|
||||
........#....#..##.#.#.......#.
|
||||
.#.......##.......#..##...#....
|
||||
...#..##..#......##.#..#.#..#..
|
||||
.#..#.......#..##..#......#....
|
||||
###.#.........#......#.#.......
|
||||
...#......#....#..##..#.#..#...
|
||||
......#..#.....#.........#....#
|
||||
....#..#..#..#.........##.#..#.
|
||||
......#..#..#..#....#...#..##.#
|
||||
......##.#..#..#.#.......#.#.##
|
||||
..#.....#...#..#....#..........
|
||||
.##..##.....##.......#.##.#....
|
||||
...#..#.......#..#.......#.....
|
||||
.........#....##..#.#....#.#...
|
||||
.....#..#...#.........#....#..#
|
||||
.........##.....#.#...#.###...#
|
||||
.#......####..##...#..#........
|
||||
.#......##....#.....#..........
|
||||
##.......##.#.......#..........
|
||||
.#......#.#.#.#....#........#..
|
||||
......##..##...#...#...........
|
||||
.#...#.#..#......#.#.#.#....#.#
|
||||
...#.........#.....#...###.....
|
||||
#.....##....#.##...#....#......
|
||||
.#..#...#..##.###.#.#.#...#....
|
||||
...#......#..#....#...#...#....
|
||||
.#..............#.....#........
|
||||
..##...#.....#..#.....#..#.#...
|
||||
.##...#....#.##...#.........##.
|
||||
..#......#...##..#.....#......#
|
||||
#.#..............#...#...#..#.#
|
||||
..#..#.#...........#...#.#.#...
|
||||
#..........#...#..#..##..#....#
|
||||
............#...#........###...
|
||||
.........#.....#.....#..#......
|
||||
#...#.#..##......#.#####.......
|
||||
...#........#..............#...
|
||||
......###.#.#.....#..#....##.#.
|
||||
.#.#.#..##....###.#..#....##...
|
||||
.#....#.##............##.#.....
|
||||
##...##.#......#.#.##.##...###.
|
||||
.......#.#........#.....#......
|
||||
....#.....#......#...#.#..#....
|
||||
.#.........#....#...#...#...#.#
|
||||
#.......#................#..#..
|
||||
.##...........#.##...##....#...
|
||||
#...#.#...###.........#.......#
|
||||
.#...#.........................
|
||||
#.......#...#.....##.##...##...
|
||||
.#.#....#.......#.#.##.#....#..
|
||||
#..#....#...#.#.##.#....#....#.
|
||||
.##.....#.#..#...#..#..........
|
||||
.............#...#.#..#........
|
||||
....#........#..#......##......
|
||||
#.....#....#.....#.......#.....
|
||||
........#.......##....#........
|
||||
.#.#..##.......................
|
||||
##..#.....#........#.....#.....
|
||||
.#......#.#...#.#..........#..#
|
||||
.#..#.....#..#..........#.###..
|
||||
......#.#..#.#.......#.#.....#.
|
||||
.#....#......#..##.............
|
||||
#...##.........#.#.#...#.....#.
|
||||
..#................#..#..###...
|
||||
#.....#....##.#..##......#.#.#.
|
||||
..#....#...#...#...............
|
||||
#................#....#...#.#..
|
||||
................#...#.....#.##.
|
||||
..#.#.#..#.##.......##.......##
|
||||
...........#......##.......###.
|
||||
...#.......##.........#.#.#.#..
|
||||
.#...#.#..#...#.#.....#........
|
||||
............#####......##......
|
||||
....###....#.##...#..#.........
|
||||
..#.#...#.......#...#...#.###..
|
||||
..............##..#...#....#...
|
||||
#.#..##...#....##.........#....
|
||||
..#...#.....#...........#...#..
|
||||
#.#..###..#.#..#........#..#.#.
|
||||
...###...##...#...#.#.........#
|
||||
..#........#.....#.#.#.......#.
|
||||
...#..#..........#.....#...#...
|
||||
....#..#.....#....##....#.##...
|
||||
.....##..#...#.#..##...#...##.#
|
||||
...........###...##....#.......
|
||||
##..#.#..#..#...#....##..#..#..
|
||||
##...#.#......##.#..#...#....#.
|
||||
.#.......#...........#...#.....
|
||||
#...#....#.......#...#.##......
|
||||
.........#.......#...#.#...#...
|
||||
.......##.#..................#.
|
||||
........#..#.#......#.....#....
|
||||
.....#.#.#.#....##...#.###.....
|
||||
#.#.........#..#.#.#.#.#.......
|
||||
.............#....#.......###..
|
||||
.#.##....#....##.........####..
|
||||
...........###.#...............
|
||||
#.........##.#.#..#.....##.###.
|
||||
.#.#.....#.#...#.....##...#...#
|
||||
#....#...#.........#.#.......#.
|
||||
.....#.###..#....#...##..#...#.
|
||||
#........#....#.#..#....#.#....
|
||||
#.#..##......#.........#.#.....
|
||||
##..#.....#......###....#....#.
|
||||
#.#.####..#.#.#......##...#..#.
|
||||
....#.....#.#.#.#.....#........
|
||||
..##..........#......#.#.#..#..
|
||||
.#...##.##.........#.........##
|
||||
..#.#.#..........#..#..#......#
|
||||
###..###..#...#................
|
11
2020/day03/testinput
Normal file
11
2020/day03/testinput
Normal file
@ -0,0 +1,11 @@
|
||||
..##.......
|
||||
#...#...#..
|
||||
.#....#..#.
|
||||
..#.#...#.#
|
||||
.#...##..#.
|
||||
..#.##.....
|
||||
.#.#.#....#
|
||||
.#........#
|
||||
#.##...#...
|
||||
#...##....#
|
||||
.#..#...#.#
|
Loading…
Reference in New Issue
Block a user