diff options
author | tomsmeding <tom.smeding@gmail.com> | 2017-12-13 09:33:20 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2017-12-13 09:33:20 +0100 |
commit | c56796a2ebe192fe0832b4e5000e900fcfd5fa40 (patch) | |
tree | d260de4424b0298cdda79884d85185ad7435f90b /2017 | |
parent | 685cd03f19eef60dbd4079ff79fbedb2e344ca1f (diff) |
Day 13
Diffstat (limited to '2017')
-rw-r--r-- | 2017/.gitignore | 1 | ||||
-rw-r--r-- | 2017/13.hs | 21 | ||||
-rw-r--r-- | 2017/13.in | 43 |
3 files changed, 65 insertions, 0 deletions
diff --git a/2017/.gitignore b/2017/.gitignore index 7d8d720..b8318ef 100644 --- a/2017/.gitignore +++ b/2017/.gitignore @@ -2,3 +2,4 @@ *.o *.dSYM ? +?? diff --git a/2017/13.hs b/2017/13.hs new file mode 100644 index 0000000..77254ca --- /dev/null +++ b/2017/13.hs @@ -0,0 +1,21 @@ +import Control.Monad +import Data.Char +import Data.List +import Data.Maybe + + +l2t :: [a] -> (a,a) +l2t [a,b] = (a,b) + +check :: [(Int, Int)] -> Int -> Bool +check inp off = all (\(d,r) -> if (d + off) `mod` (2 * (r - 1)) == 0 then False else True) inp + +cost :: [(Int, Int)] -> Int -> Int +cost inp off = sum $ map (\(d,r) -> if (d + off) `mod` (2 * (r - 1)) == 0 then d * r else 0) inp + +main :: IO () +main = do + input <- liftM (map (l2t . map (read . takeWhile isDigit) . words) . lines) (readFile "13.in") + + print $ cost input 0 + print $ fromJust $ findIndex id $ map (check input) [0..] diff --git a/2017/13.in b/2017/13.in new file mode 100644 index 0000000..a1de9f9 --- /dev/null +++ b/2017/13.in @@ -0,0 +1,43 @@ +0: 3 +1: 2 +2: 6 +4: 4 +6: 4 +8: 8 +10: 9 +12: 8 +14: 5 +16: 6 +18: 8 +20: 6 +22: 12 +24: 6 +26: 12 +28: 8 +30: 8 +32: 10 +34: 12 +36: 12 +38: 8 +40: 12 +42: 12 +44: 14 +46: 12 +48: 14 +50: 12 +52: 12 +54: 12 +56: 10 +58: 14 +60: 14 +62: 14 +64: 14 +66: 17 +68: 14 +72: 14 +76: 14 +80: 14 +82: 14 +88: 18 +92: 14 +98: 18 |