[hs] Clean up 2020 days
This commit is contained in:
parent
23636d3fc0
commit
c48319423d
3 changed files with 16 additions and 10 deletions
|
|
@ -31,8 +31,9 @@ solver values = do
|
|||
let (x1, x2) = findPair values
|
||||
putStrLn $ show x1 ++ " * " ++ show x2 ++ " = " ++ show (x1 * x2)
|
||||
|
||||
let (y1, y2, y3) = findTriple values
|
||||
putStrLn ""
|
||||
putStrLn ">> Part 2"
|
||||
let (y1, y2, y3) = findTriple values
|
||||
putStrLn $ show y1 ++ " * " ++ show y2 ++ " * " ++ show y3 ++ " = " ++ show (y1 * y2 * y3)
|
||||
|
||||
day :: Day
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ module Aoc.Y2020.D02
|
|||
( day
|
||||
) where
|
||||
|
||||
import qualified Data.Text as T
|
||||
import qualified Data.Text as T
|
||||
|
||||
import Aoc.Day
|
||||
import Aoc.Parse
|
||||
|
|
@ -37,6 +37,7 @@ solver ls = do
|
|||
putStrLn ">> Part 1"
|
||||
print $ length $ filter validCount ls
|
||||
|
||||
putStrLn ""
|
||||
putStrLn ">> Part 2"
|
||||
print $ length $ filter validPositions ls
|
||||
|
||||
|
|
|
|||
|
|
@ -7,18 +7,21 @@ import Data.List
|
|||
import Aoc.Day
|
||||
import Aoc.Parse
|
||||
|
||||
parser :: Parser [[Bool]]
|
||||
type Forest = [[Bool]]
|
||||
type Slope = [Maybe Int]
|
||||
|
||||
parser :: Parser Forest
|
||||
parser = manyLines $ many $ do
|
||||
c <- lineChar
|
||||
pure $ c == '#'
|
||||
|
||||
slope :: Int -> Int -> [Maybe Int]
|
||||
slope :: Int -> Int -> Slope
|
||||
slope dx dy = intercalate (replicate (dy - 1) Nothing) [[Just x] | x <- [0,dx..]]
|
||||
|
||||
onSlope :: [[Bool]] -> [Maybe Int] -> Int
|
||||
onSlope trees s = length $ filter id $ [row !! x | (row, Just x) <- zip trees s]
|
||||
onSlope :: Forest -> Slope -> Int
|
||||
onSlope trees s = length $ filter id [row !! x | (row, Just x) <- zip trees s]
|
||||
|
||||
solver :: [[Bool]] -> IO ()
|
||||
solver :: Forest -> IO ()
|
||||
solver trees = do
|
||||
let infTrees = map cycle trees
|
||||
|
||||
|
|
@ -26,12 +29,13 @@ solver trees = do
|
|||
let treesHit = length $ filter id $ zipWith (!!) infTrees [0,3..]
|
||||
putStrLn $ "Trees hit for slope 3-1: " ++ show treesHit
|
||||
|
||||
putStrLn ""
|
||||
putStrLn ">> Part 2"
|
||||
let oneOne = onSlope infTrees $ slope 1 1
|
||||
let oneOne = onSlope infTrees $ slope 1 1
|
||||
threeOne = onSlope infTrees $ slope 3 1
|
||||
fiveOne = onSlope infTrees $ slope 5 1
|
||||
fiveOne = onSlope infTrees $ slope 5 1
|
||||
sevenOne = onSlope infTrees $ slope 7 1
|
||||
oneTwo = onSlope infTrees $ slope 1 2
|
||||
oneTwo = onSlope infTrees $ slope 1 2
|
||||
putStrLn $ "right 1, down 1: " ++ show oneOne
|
||||
putStrLn $ "right 3, down 1: " ++ show threeOne
|
||||
putStrLn $ "right 5, down 1: " ++ show fiveOne
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue