Initial commit
This commit is contained in:
commit
f242d2b0df
420 changed files with 62521 additions and 0 deletions
31
2017/13/day13.hs
Normal file
31
2017/13/day13.hs
Normal file
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/env stack
|
||||
-- stack --resolver lts-9.18 script --package ghc --package text
|
||||
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as T
|
||||
import Util (filterByList)
|
||||
import Data.List
|
||||
|
||||
caught :: [Int] -> [Int] -> [Bool]
|
||||
caught = zipWith (\d k -> d `rem` (2*(k-1)) == 0)
|
||||
|
||||
severity :: [Int] -> [Int] -> [Bool] -> Int
|
||||
severity depths ranges catches =
|
||||
sum $ zipWith (*) depths' ranges'
|
||||
where depths' = filterByList catches depths
|
||||
ranges' = filterByList catches ranges
|
||||
|
||||
findDelay :: Int -> [Int] -> [Int] -> Int
|
||||
findDelay dt depths ranges =
|
||||
if not . or $ caught (map (+dt) depths) ranges then
|
||||
dt
|
||||
else findDelay (dt+1) depths ranges
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
contents <- T.lines . T.pack <$> getContents
|
||||
let depths:ranges:_ = transpose $ map (read . T.unpack) . T.splitOn ": " <$> contents
|
||||
putStrLn . show $ severity depths ranges (caught depths ranges)
|
||||
putStrLn . show $ findDelay 0 depths ranges
|
||||
|
43
2017/13/input.txt
Normal file
43
2017/13/input.txt
Normal file
|
@ -0,0 +1,43 @@
|
|||
0: 3
|
||||
1: 2
|
||||
2: 4
|
||||
4: 4
|
||||
6: 5
|
||||
8: 6
|
||||
10: 6
|
||||
12: 8
|
||||
14: 6
|
||||
16: 6
|
||||
18: 9
|
||||
20: 8
|
||||
22: 8
|
||||
24: 8
|
||||
26: 12
|
||||
28: 8
|
||||
30: 12
|
||||
32: 12
|
||||
34: 12
|
||||
36: 10
|
||||
38: 14
|
||||
40: 12
|
||||
42: 10
|
||||
44: 8
|
||||
46: 12
|
||||
48: 14
|
||||
50: 12
|
||||
52: 14
|
||||
54: 14
|
||||
56: 14
|
||||
58: 12
|
||||
62: 14
|
||||
64: 12
|
||||
66: 12
|
||||
68: 14
|
||||
70: 14
|
||||
72: 14
|
||||
74: 17
|
||||
76: 14
|
||||
78: 18
|
||||
84: 14
|
||||
90: 20
|
||||
92: 14
|
Loading…
Add table
Add a link
Reference in a new issue