day 3
This commit is contained in:
parent
d54a5d514d
commit
dd2bcc94a5
40
day3.hs
Normal file
40
day3.hs
Normal 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
day3.txt
Normal file
323
day3.txt
Normal file
@ -0,0 +1,323 @@
|
||||
..#..#......#..#.......#...#.#.
|
||||
...##.....##..#..#....#.##.##.#
|
||||
...#...#.##...##.....#.....#.#.
|
||||
..#....#.....#...##.##.###.#...
|
||||
.#.....#......#..#.##.#...###..
|
||||
#..#..#.#......#...........###.
|
||||
#......####.#....##........##..
|
||||
.#.......#.....#......#...#....
|
||||
...#...#.....#.......##.....##.
|
||||
#...##.........#.#..##..#..#.##
|
||||
#.#.##.........#.#..#.#.....###
|
||||
.##..##...#....##.....#..#.....
|
||||
........#.......###.#.#.....#.#
|
||||
...#.#....#.##..#...##..##..#..
|
||||
......#....#........######.#...
|
||||
.##...#.#...###......#.#.#..#.#
|
||||
........#.##...##.#...#..#...##
|
||||
.#..#.#..##....###..#.#.......#
|
||||
..#..##..#.#...#.##......#.....
|
||||
##.....#..##.#.#..#......##...#
|
||||
......................#..#..#..
|
||||
..#.##....####.........###.##..
|
||||
##..###..#...#....#..#.#...#...
|
||||
.##.#......#..#....#........#..
|
||||
.#.....#..#..#.#.#....#.....##.
|
||||
..........#..#....#..##...#..##
|
||||
.#...#.#....#.##..#.....#....#.
|
||||
#..............#.#.#..#..#....#
|
||||
...#.#...............##........
|
||||
#.#.##...#.##..##.....#........
|
||||
...#.......###..###..#...#..#..
|
||||
####..#.#..##.....##.#.#......#
|
||||
.#.#.......#..##.......#.......
|
||||
#....#...#.##.#.......#..#.....
|
||||
.#...##..#..#..##.......##...#.
|
||||
.#..#......#.........#.........
|
||||
#.##.#.....#....#..##..#.....#.
|
||||
#.#....#.#....#...#.#..#....#..
|
||||
#..#.....#.##..#.....#...##...#
|
||||
#....#...##.#.........#.#....##
|
||||
.......##.##......##.......##..
|
||||
#.....#..#........#........#...
|
||||
#....#.#..#.#........##.#...#..
|
||||
#.......#.#.#.#....#.......##.#
|
||||
...#..###..........#...#.#.###.
|
||||
....#..#....#...#....##.#.....#
|
||||
.#..##.....#..#....##..##...#.#
|
||||
#.........#....#.#..###...##...
|
||||
.#.#.........#.#.......#.#.#..#
|
||||
..........#........##..#.......
|
||||
.....#.......#...#.....#..##.##
|
||||
...#.........#.............####
|
||||
##..#...#..#.#......#...#......
|
||||
.#..###...#.#.#.#...#...#......
|
||||
....#..##.#....#..#.#..##..##.#
|
||||
..#.......#......#..#.......#..
|
||||
....###......#...##...#....#...
|
||||
..#..#.....#...#..###....#.#..#
|
||||
.........##..#.##....#..##..#..
|
||||
##...#...#.#.........##......#.
|
||||
###..#.#....#......##..##.#...#
|
||||
.##...##..#.#.#.#......#..#....
|
||||
###......#..#..#.....#..#....#.
|
||||
.#.#..##....##........##..#.#..
|
||||
###...####.#....#.......###....
|
||||
..#....###..#.#.#..#.......##..
|
||||
.......#.#...#.....#.#....##.#.
|
||||
......#......#.#....#..##..###.
|
||||
....####..........#.....#......
|
||||
.###.....#...#..#...##.#...###.
|
||||
...##....##....###....#.#..#.#.
|
||||
##.#..........##.........#.##..
|
||||
..#..#.#.###..##..#....##.....#
|
||||
..#....##.....#...##....###..##
|
||||
....#.......##..#..#..........#
|
||||
............#..#.###..#.#......
|
||||
...........##......#.#.#...#..#
|
||||
...##.##....#...##.##.....#.#..
|
||||
.####...#....###...#.....#....#
|
||||
.##........#..##..#.#.....#....
|
||||
..................#.....#..##..
|
||||
..###.....#.##..#..#....##...#.
|
||||
...#.##.#.####.#.###.#....#..##
|
||||
.#....##..##......####.#####...
|
||||
#...#.#....##.........##....#..
|
||||
..#.##.....##.............#.##.
|
||||
###.....#.#..#..#......#.##.#..
|
||||
...#..##.....#...##...#......#.
|
||||
.##.#...#......##.#..##....#...
|
||||
.....##.....#......#.#.........
|
||||
#.....#.....#........##........
|
||||
.#......##...#..#.#....###.#..#
|
||||
#.####...#....#.........#..#...
|
||||
#..##.#.....#.##.##.#....#...#.
|
||||
#########..#....#..#...#......#
|
||||
..##..##...###.######...##.##..
|
||||
##.......#.......#.#....###..#.
|
||||
.....#...#.######..#.....#.....
|
||||
.#......#..#.............#.##.#
|
||||
..###.#.#......##...###........
|
||||
.......####.#..##....#........#
|
||||
..#......#.##....##.##....#....
|
||||
....#......#.#....#..#.#.....##
|
||||
####.....#....#.#......#.#.#.##
|
||||
#...##....#.#.##.........#....#
|
||||
....#..###......#......#...#...
|
||||
.....##.#..#..#...#..#.#.#.....
|
||||
.##............#.....#.........
|
||||
##...#..#.....##.#..#..........
|
||||
#.....#####.......#..#....#.#..
|
||||
.........#..#.....###........#.
|
||||
#....#..#...###........#..#.#..
|
||||
...##...#..#...#.##..#.........
|
||||
.........#.#.....#.......#...#.
|
||||
.#.....#..####....#.##.......##
|
||||
...............##....##.##..##.
|
||||
............#....#....#...##.#.
|
||||
..#...#........#.......#..#....
|
||||
##....####....#.##...#..##..#.#
|
||||
.#.#.....#......#.#........#.#.
|
||||
....#......#.#....##..##.......
|
||||
.#..#.#..#..##.....#...........
|
||||
..#........#.##..#......##..#..
|
||||
...##.#...#...#..#........#....
|
||||
##..##....#......#...#..#.#.#.#
|
||||
......#.....#..#..#....#.......
|
||||
.....##......#..#.#.##...#.....
|
||||
...#.....#.#..........#..##...#
|
||||
.####.##....#...........#.....#
|
||||
.....###..##...#....##..#...#..
|
||||
..##...#.#...#..........#..#.#.
|
||||
...#..#..............#.##.#....
|
||||
##.#....#...#..#....#..........
|
||||
.##..........#..#........#.....
|
||||
#...#.#......#...#.....##..#...
|
||||
.##...#.#.#....###.####..#....#
|
||||
.#......#.#...#.#....#.#...#...
|
||||
#....##.###.............#.#....
|
||||
....#.###..##..##.##...##......
|
||||
##....#..###.##.##.....#......#
|
||||
..#..#..#......#..#..#.........
|
||||
#.##......#.#....#..#..#.......
|
||||
....#.#...#..###......##.......
|
||||
.###.......##.......#....###...
|
||||
..#..#.##..#.#....#..#.#.....#.
|
||||
.#..##.##..............#....#..
|
||||
#...#.#...#..#.##..##.#.#......
|
||||
#...#..#..##..##.###......#....
|
||||
.#..#.....#...#....#.....#...#.
|
||||
.....#....#..#.....###...#.####
|
||||
.#.....#......#...##...#..#....
|
||||
.#......#............#.#.......
|
||||
....##....#.#..#..#...#..#.#...
|
||||
#...#.....###...##...#.##.....#
|
||||
.......#.....#....#.......#...#
|
||||
#.......###.......#.#..........
|
||||
...#.#.###.#........#.###...#..
|
||||
....#............#....#..#.....
|
||||
#......#.##.#...##.......#..#.#
|
||||
.....#....#....#.#.#...###..#..
|
||||
.....#.#...#...#.#..#....#.#..#
|
||||
.#.......#.#..#...###.......##.
|
||||
.......#..#.##.........#.......
|
||||
.##.#........#.##...##....#....
|
||||
.#....#..#...#......####...#..#
|
||||
...#.....#..##.#..#.#....#....#
|
||||
...##....#........#.#........#.
|
||||
.....#....##..#.##..........#..
|
||||
#.....#.#.#......##....##.#..#.
|
||||
.#.#.##..#.#....##.#....##.....
|
||||
.....#.....#..#.#....#..#....##
|
||||
...#........#....#......###.#..
|
||||
.....##...#.....##.##.#.#.##...
|
||||
...#.....#####....##.#.#.###.#.
|
||||
.#..#.#..##...###.........#.#.#
|
||||
#...#...#.#..#...#...........#.
|
||||
.##..............#...#..#....#.
|
||||
....###.........#.#.#....#.....
|
||||
..#...##.#.#....##.#..#...#..#.
|
||||
..#.....#.#......#....#......#.
|
||||
.......##....#.#.##....#...#..#
|
||||
##.#.#...#..#......#..#..#....#
|
||||
...#.#......#............###.##
|
||||
..###..#..##..#...##........#..
|
||||
.#...#...##...#....#....##.#..#
|
||||
..##...####....#....#..#....#.#
|
||||
...#......##....#.........##.#.
|
||||
##.#.......#..#..#.............
|
||||
..#.#.#.#......#...#.#..##.....
|
||||
.#..##.....###...##.#..#......#
|
||||
##...#..........#.####....##...
|
||||
#..........#...#..##....#......
|
||||
....##...#....#..####...#.##.##
|
||||
.#.######...##...#..##.........
|
||||
....##.........#.......##.##...
|
||||
.#.....#.#..........##......#..
|
||||
...#..#.#.###..#........#.....#
|
||||
..##..#............##.......#..
|
||||
......##....##..#.##..#.......#
|
||||
.......##....#.......#..#...#.#
|
||||
#.#......#.###.....#.##........
|
||||
.#..##..........#..#.....#.##..
|
||||
..#.#...#....#.........#..##..#
|
||||
.#......#.......#...#..#..###..
|
||||
......#.##.....#.#......#....#.
|
||||
....#....#...#.......#...##.##.
|
||||
#....#...##...#..##........###.
|
||||
##......#.#..#.......#.......#.
|
||||
...##.##..#......#.###..#.#.##.
|
||||
.............#..#.............#
|
||||
..#.......##..#..#....##...#...
|
||||
...............##..##........#.
|
||||
##...#.##.......#....#.......##
|
||||
....##.##.#.#.....##.....##.##.
|
||||
#.#......#.......#..#.#..#.....
|
||||
....##....#.##........##.##.#..
|
||||
......##....#..##..#..##....##.
|
||||
.............#.....#.......#...
|
||||
.......###.......#..........#..
|
||||
......##.#..#.....#.#...#.#...#
|
||||
.#...#..#..###.###...#....##...
|
||||
#......#..#.#...#...#.....#..##
|
||||
.###.....#..#.#......##..#.##..
|
||||
.##.#.....#..#.#..#....##......
|
||||
#......#..............#.....#.#
|
||||
...#..#....#.....#.....##.#...#
|
||||
......#..##..##.....#...#......
|
||||
.....####..#..#.##.......#..#.#
|
||||
###.#.#........#.......#.....##
|
||||
..#.#.#.#...#...#........#....#
|
||||
....##.#.#..#...##.....#......#
|
||||
#..#.##....#..#.##..####.......
|
||||
...####.#...#......#......##..#
|
||||
#....#.#..###......#..#..##..#.
|
||||
...........#....#...#......#...
|
||||
......###.#.....#.#....#.#...#.
|
||||
.......#.##..............#..##.
|
||||
..##...........#..#.#...#.....#
|
||||
#..#............##.........#.#.
|
||||
.......###.#...#.#...#.#.#...#.
|
||||
..#...##.......#..#......#.#.##
|
||||
#.#...#.....#...##.#.#.......##
|
||||
.#.#.##...#..##.#......#.......
|
||||
#.......#.......#.#....#.....#.
|
||||
.....#..#..#.......#..#........
|
||||
##...##...##......#..##.###....
|
||||
..#...#.###.#.###..#.....###...
|
||||
.....####.......#.#.....##....#
|
||||
....#....#.#....#...#..#.#..#..
|
||||
..##.....#....#.#.#.###...#....
|
||||
......#.#....#.#..#....#.#..#..
|
||||
#...#...#....#.......#......#.#
|
||||
#..#.#......#..#...........#.##
|
||||
...............#....#.....#...#
|
||||
.#.#.#...#.##...#.#.#..#....#..
|
||||
...#.#.####..##.#...##.........
|
||||
##.........##.##.....##....#...
|
||||
................#...#.##.#.#..#
|
||||
.#..#....#...#..#..#..###.#..#.
|
||||
...#..#.##.#.####..........#..#
|
||||
........#....##......#..#.#....
|
||||
........##.........#..#..#..#.#
|
||||
#......#.#...#...#...##.....#..
|
||||
#...#.....#..#..##.#...#.#.#...
|
||||
....#..##...##.....#...#.#.....
|
||||
..#..##....#....#...#....#.....
|
||||
.#..#...##.......###...#...#...
|
||||
.#......#......#..##..#..##....
|
||||
....##....#..#.#....#.#..##....
|
||||
###......#...........#.....###.
|
||||
.....#...#..##.#..#..#.....#..#
|
||||
#.#....#...........#.##..#..###
|
||||
#....#...###.#...#..##..#.....#
|
||||
.#....#......##.#..#....#.#....
|
||||
....#.#....#..#.#....#..#..#...
|
||||
..#......#..#.#.#....#.........
|
||||
.#...#.#.....#........#.#...###
|
||||
....#..##.......#.###....##....
|
||||
#.#.......#......#.###........#
|
||||
#.........#.....####.##..#..#..
|
||||
.#.#..##...#.#.....##.#.#..#...
|
||||
.#..#..#..#.##..#...###.#...#..
|
||||
.....##..##..##..#.#.#.....###.
|
||||
.#..#...#..#......##.#.........
|
||||
....#..##....#.##.........#...#
|
||||
........#...#...###.........##.
|
||||
#.........#..##....#.#...#.....
|
||||
.......#.......#..#.......#....
|
||||
#......##......#.#.##..........
|
||||
.#..##..####...#.....####.....#
|
||||
........#.#....#..##..###.#...#
|
||||
.#...#...#.........###..#...#.#
|
||||
#.........#....##...#..........
|
||||
.#.#....#..........#...........
|
||||
.#.#..........#.##.....#.##....
|
||||
..#....#...##..###..........##.
|
||||
.#.#..#.##..#..#.##.##..##.....
|
||||
........#...#....#...#.#..##...
|
||||
......#......##..#..#.....#..#.
|
||||
.##.#....#...#....#...#..##..##
|
||||
##............#..........###...
|
||||
....#.......#.#..#.#####.....#.
|
||||
#......#.....#...#........#....
|
||||
..##.....###..#.#.#.#....#....#
|
||||
#...#...#.#..#..#....#..#......
|
||||
......#....#...#..#....#####...
|
||||
....#.......##....#....##......
|
||||
.....##...#.##.#.....##....#...
|
||||
.#....###.#..##...##.##.......#
|
||||
....#.#.#.##.............#..##.
|
||||
...........##......#...#.#.##..
|
||||
....##......#....#....##..##.#.
|
||||
.#.#...#.....##.....#.........#
|
||||
#.#..........#.......#.##...#..
|
||||
....#.##..#.#....#.....#...#...
|
||||
##.............##.......#.##.#.
|
||||
....#...#.....##...#..........#
|
||||
##..#...#...#.#.##...#.......##
|
||||
..#........#.....###...##..##.#
|
||||
.....#...##.#.#.##.....#...#...
|
||||
####.###...##..##...#..#..#..##
|
||||
......#..#..#.........#...#.#..
|
||||
....###.....##.##....#.##.....#
|
Loading…
Reference in New Issue
Block a user