Browse Source

day 3

master
Thorn Avery 3 years ago
parent
commit
dd2bcc94a5
2 changed files with 363 additions and 0 deletions
  1. +40
    -0
      day3.hs
  2. +323
    -0
      day3.txt

+ 40
- 0
day3.hs View File

@@ -0,0 +1,40 @@
main :: IO ()
main = do
raw <- readFile "day3.txt"
let ls = map parse $ lines raw
ansA = solveSlope 3 1 ls
ansB = foldr (*) 1 $
[ (solveSlope 1 1 ls)
, (solveSlope 3 1 ls)
, (solveSlope 5 1 ls)
, (solveSlope 7 1 ls)
, (solveSlope 1 2 ls)
]
in do
putStrLn $ "day3a: " ++ (show ansA)
putStrLn $ "day3b: " ++ (show ansB)

parse :: String -> [Bool]
parse = map (== '#')

solveLine :: [Bool] -> Int -> Bool
solveLine [] _ = error "empty list"
solveLine bs i = bs !! index
where
index = i `mod` (length bs)

solveSlope :: Int -> Int -> [[Bool]] -> Int
solveSlope r d bs =
length $ filter (== True) $ solveSlope' r d bs 0 []

solveSlope' :: Int -> Int -> [[Bool]] -> Int -> [Bool] -> [Bool]
solveSlope' _ _ [] _ as = as
solveSlope' r d bs@(b:cs) i as =
if ns == []
then as
else solveSlope' r d ns ni $ (solveLine (head ns) ni) : as
where
ni = (i + r) `mod` (length b)
ns = if (length bs) <= d
then []
else (drop d bs)

+ 323
- 0
day3.txt View File

@@ -0,0 +1,323 @@
..#..#......#..#.......#...#.#.
...##.....##..#..#....#.##.##.#
...#...#.##...##.....#.....#.#.
..#....#.....#...##.##.###.#...
.#.....#......#..#.##.#...###..
#..#..#.#......#...........###.
#......####.#....##........##..
.#.......#.....#......#...#....
...#...#.....#.......##.....##.
#...##.........#.#..##..#..#.##
#.#.##.........#.#..#.#.....###
.##..##...#....##.....#..#.....
........#.......###.#.#.....#.#
...#.#....#.##..#...##..##..#..
......#....#........######.#...
.##...#.#...###......#.#.#..#.#
........#.##...##.#...#..#...##
.#..#.#..##....###..#.#.......#
..#..##..#.#...#.##......#.....
##.....#..##.#.#..#......##...#
......................#..#..#..
..#.##....####.........###.##..
##..###..#...#....#..#.#...#...
.##.#......#..#....#........#..
.#.....#..#..#.#.#....#.....##.
..........#..#....#..##...#..##
.#...#.#....#.##..#.....#....#.
#..............#.#.#..#..#....#
...#.#...............##........
#.#.##...#.##..##.....#........
...#.......###..###..#...#..#..
####..#.#..##.....##.#.#......#
.#.#.......#..##.......#.......
#....#...#.##.#.......#..#.....
.#...##..#..#..##.......##...#.
.#..#......#.........#.........
#.##.#.....#....#..##..#.....#.
#.#....#.#....#...#.#..#....#..
#..#.....#.##..#.....#...##...#
#....#...##.#.........#.#....##
.......##.##......##.......##..
#.....#..#........#........#...
#....#.#..#.#........##.#...#..
#.......#.#.#.#....#.......##.#
...#..###..........#...#.#.###.
....#..#....#...#....##.#.....#
.#..##.....#..#....##..##...#.#
#.........#....#.#..###...##...
.#.#.........#.#.......#.#.#..#
..........#........##..#.......
.....#.......#...#.....#..##.##
...#.........#.............####
##..#...#..#.#......#...#......
.#..###...#.#.#.#...#...#......
....#..##.#....#..#.#..##..##.#
..#.......#......#..#.......#..
....###......#...##...#....#...
..#..#.....#...#..###....#.#..#
.........##..#.##....#..##..#..
##...#...#.#.........##......#.
###..#.#....#......##..##.#...#
.##...##..#.#.#.#......#..#....
###......#..#..#.....#..#....#.
.#.#..##....##........##..#.#..
###...####.#....#.......###....
..#....###..#.#.#..#.......##..
.......#.#...#.....#.#....##.#.
......#......#.#....#..##..###.
....####..........#.....#......
.###.....#...#..#...##.#...###.
...##....##....###....#.#..#.#.
##.#..........##.........#.##..
..#..#.#.###..##..#....##.....#
..#....##.....#...##....###..##
....#.......##..#..#..........#
............#..#.###..#.#......
...........##......#.#.#...#..#
...##.##....#...##.##.....#.#..
.####...#....###...#.....#....#
.##........#..##..#.#.....#....
..................#.....#..##..
..###.....#.##..#..#....##...#.
...#.##.#.####.#.###.#....#..##
.#....##..##......####.#####...
#...#.#....##.........##....#..
..#.##.....##.............#.##.
###.....#.#..#..#......#.##.#..
...#..##.....#...##...#......#.
.##.#...#......##.#..##....#...
.....##.....#......#.#.........
#.....#.....#........##........
.#......##...#..#.#....###.#..#
#.####...#....#.........#..#...
#..##.#.....#.##.##.#....#...#.
#########..#....#..#...#......#
..##..##...###.######...##.##..
##.......#.......#.#....###..#.
.....#...#.######..#.....#.....
.#......#..#.............#.##.#
..###.#.#......##...###........
.......####.#..##....#........#
..#......#.##....##.##....#....
....#......#.#....#..#.#.....##
####.....#....#.#......#.#.#.##
#...##....#.#.##.........#....#
....#..###......#......#...#...
.....##.#..#..#...#..#.#.#.....
.##............#.....#.........
##...#..#.....##.#..#..........
#.....#####.......#..#....#.#..
.........#..#.....###........#.
#....#..#...###........#..#.#..
...##...#..#...#.##..#.........
.........#.#.....#.......#...#.
.#.....#..####....#.##.......##
...............##....##.##..##.
............#....#....#...##.#.
..#...#........#.......#..#....
##....####....#.##...#..##..#.#
.#.#.....#......#.#........#.#.
....#......#.#....##..##.......
.#..#.#..#..##.....#...........
..#........#.##..#......##..#..
...##.#...#...#..#........#....
##..##....#......#...#..#.#.#.#
......#.....#..#..#....#.......
.....##......#..#.#.##...#.....
...#.....#.#..........#..##...#
.####.##....#...........#.....#
.....###..##...#....##..#...#..
..##...#.#...#..........#..#.#.
...#..#..............#.##.#....
##.#....#...#..#....#..........
.##..........#..#........#.....
#...#.#......#...#.....##..#...
.##...#.#.#....###.####..#....#
.#......#.#...#.#....#.#...#...
#....##.###.............#.#....
....#.###..##..##.##...##......
##....#..###.##.##.....#......#
..#..#..#......#..#..#.........
#.##......#.#....#..#..#.......
....#.#...#..###......##.......
.###.......##.......#....###...
..#..#.##..#.#....#..#.#.....#.
.#..##.##..............#....#..
#...#.#...#..#.##..##.#.#......
#...#..#..##..##.###......#....
.#..#.....#...#....#.....#...#.
.....#....#..#.....###...#.####
.#.....#......#...##...#..#....
.#......#............#.#.......
....##....#.#..#..#...#..#.#...
#...#.....###...##...#.##.....#
.......#.....#....#.......#...#
#.......###.......#.#..........
...#.#.###.#........#.###...#..
....#............#....#..#.....
#......#.##.#...##.......#..#.#
.....#....#....#.#.#...###..#..
.....#.#...#...#.#..#....#.#..#
.#.......#.#..#...###.......##.
.......#..#.##.........#.......
.##.#........#.##...##....#....
.#....#..#...#......####...#..#
...#.....#..##.#..#.#....#....#
...##....#........#.#........#.
.....#....##..#.##..........#..
#.....#.#.#......##....##.#..#.
.#.#.##..#.#....##.#....##.....
.....#.....#..#.#....#..#....##
...#........#....#......###.#..
.....##...#.....##.##.#.#.##...
...#.....#####....##.#.#.###.#.
.#..#.#..##...###.........#.#.#
#...#...#.#..#...#...........#.
.##..............#...#..#....#.
....###.........#.#.#....#.....
..#...##.#.#....##.#..#...#..#.
..#.....#.#......#....#......#.
.......##....#.#.##....#...#..#
##.#.#...#..#......#..#..#....#
...#.#......#............###.##
..###..#..##..#...##........#..
.#...#...##...#....#....##.#..#
..##...####....#....#..#....#.#
...#......##....#.........##.#.
##.#.......#..#..#.............
..#.#.#.#......#...#.#..##.....
.#..##.....###...##.#..#......#
##...#..........#.####....##...
#..........#...#..##....#......
....##...#....#..####...#.##.##
.#.######...##...#..##.........
....##.........#.......##.##...
.#.....#.#..........##......#..
...#..#.#.###..#........#.....#
..##..#............##.......#..
......##....##..#.##..#.......#
.......##....#.......#..#...#.#
#.#......#.###.....#.##........
.#..##..........#..#.....#.##..
..#.#...#....#.........#..##..#
.#......#.......#...#..#..###..
......#.##.....#.#......#....#.
....#....#...#.......#...##.##.
#....#...##...#..##........###.
##......#.#..#.......#.......#.
...##.##..#......#.###..#.#.##.
.............#..#.............#
..#.......##..#..#....##...#...
...............##..##........#.
##...#.##.......#....#.......##
....##.##.#.#.....##.....##.##.
#.#......#.......#..#.#..#.....
....##....#.##........##.##.#..
......##....#..##..#..##....##.
.............#.....#.......#...
.......###.......#..........#..
......##.#..#.....#.#...#.#...#
.#...#..#..###.###...#....##...
#......#..#.#...#...#.....#..##
.###.....#..#.#......##..#.##..
.##.#.....#..#.#..#....##......
#......#..............#.....#.#
...#..#....#.....#.....##.#...#
......#..##..##.....#...#......
.....####..#..#.##.......#..#.#
###.#.#........#.......#.....##
..#.#.#.#...#...#........#....#
....##.#.#..#...##.....#......#
#..#.##....#..#.##..####.......
...####.#...#......#......##..#
#....#.#..###......#..#..##..#.
...........#....#...#......#...
......###.#.....#.#....#.#...#.
.......#.##..............#..##.
..##...........#..#.#...#.....#
#..#............##.........#.#.
.......###.#...#.#...#.#.#...#.
..#...##.......#..#......#.#.##
#.#...#.....#...##.#.#.......##
.#.#.##...#..##.#......#.......
#.......#.......#.#....#.....#.
.....#..#..#.......#..#........
##...##...##......#..##.###....
..#...#.###.#.###..#.....###...
.....####.......#.#.....##....#
....#....#.#....#...#..#.#..#..
..##.....#....#.#.#.###...#....
......#.#....#.#..#....#.#..#..
#...#...#....#.......#......#.#
#..#.#......#..#...........#.##
...............#....#.....#...#
.#.#.#...#.##...#.#.#..#....#..
...#.#.####..##.#...##.........
##.........##.##.....##....#...
................#...#.##.#.#..#
.#..#....#...#..#..#..###.#..#.
...#..#.##.#.####..........#..#
........#....##......#..#.#....
........##.........#..#..#..#.#
#......#.#...#...#...##.....#..
#...#.....#..#..##.#...#.#.#...
....#..##...##.....#...#.#.....
..#..##....#....#...#....#.....
.#..#...##.......###...#...#...
.#......#......#..##..#..##....
....##....#..#.#....#.#..##....
###......#...........#.....###.
.....#...#..##.#..#..#.....#..#
#.#....#...........#.##..#..###
#....#...###.#...#..##..#.....#
.#....#......##.#..#....#.#....
....#.#....#..#.#....#..#..#...
..#......#..#.#.#....#.........
.#...#.#.....#........#.#...###
....#..##.......#.###....##....
#.#.......#......#.###........#
#.........#.....####.##..#..#..
.#.#..##...#.#.....##.#.#..#...
.#..#..#..#.##..#...###.#...#..
.....##..##..##..#.#.#.....###.
.#..#...#..#......##.#.........
....#..##....#.##.........#...#
........#...#...###.........##.
#.........#..##....#.#...#.....
.......#.......#..#.......#....
#......##......#.#.##..........
.#..##..####...#.....####.....#
........#.#....#..##..###.#...#
.#...#...#.........###..#...#.#
#.........#....##...#..........
.#.#....#..........#...........
.#.#..........#.##.....#.##....
..#....#...##..###..........##.
.#.#..#.##..#..#.##.##..##.....
........#...#....#...#.#..##...
......#......##..#..#.....#..#.
.##.#....#...#....#...#..##..##
##............#..........###...
....#.......#.#..#.#####.....#.
#......#.....#...#........#....
..##.....###..#.#.#.#....#....#
#...#...#.#..#..#....#..#......
......#....#...#..#....#####...
....#.......##....#....##......
.....##...#.##.#.....##....#...
.#....###.#..##...##.##.......#
....#.#.#.##.............#..##.
...........##......#...#.#.##..
....##......#....#....##..##.#.
.#.#...#.....##.....#.........#
#.#..........#.......#.##...#..
....#.##..#.#....#.....#...#...
##.............##.......#.##.#.
....#...#.....##...#..........#
##..#...#...#.#.##...#.......##
..#........#.....###...##..##.#
.....#...##.#.#.##.....#...#...
####.###...##..##...#..#..#..##
......#..#..#.........#...#.#..
....###.....##.##....#.##.....#

Loading…
Cancel
Save