Commit 85352825 authored by Nicolas Lenz's avatar Nicolas Lenz

Implement Day 1

parent 97179739
*.template
*.cabal
dist
dist-*
cabal-dev
*.o
*.hi
*.chi
*.chs.h
*.dyn_o
*.dyn_hi
.hpc
.hsenv
.cabal-sandbox/
cabal.sandbox.config
*.prof
*.aux
*.hp
*.eventlog
.stack-work/
cabal.project.local
cabal.project.local~
.HTF/
.ghc.environment.*
.vscode
71764
58877
107994
72251
74966
87584
118260
144961
86889
136710
52493
131045
101496
124341
71936
88967
106520
125454
113463
81854
99918
105217
120383
61105
103842
125151
139191
143365
102168
69845
57343
93401
140910
121997
107964
53358
57397
141456
94052
127395
99180
143838
130749
126809
70165
92007
83343
55163
95270
101323
99877
105721
129657
61213
130120
108549
90539
111382
61665
95121
53216
103144
134367
101251
105118
73220
56270
50846
77314
59134
98495
113654
89711
68676
98991
109068
129630
58999
132095
98685
91762
88589
73846
124940
106944
133882
104073
78475
76545
144728
72449
118320
65363
83523
124634
96222
128252
112848
139027
108208
name: advent-of-code
license: Apache-2.0
git: "https://git.eisfunke.com/research/advent-of-code-2019"
author: "Nicolas Lenz"
maintainer: "nicolas@eisfunke.com"
dependencies:
- base
- classy-prelude
- text
- megaparsec
default-extensions:
- NoImplicitPrelude
- OverloadedStrings
- LambdaCase
executables:
advent-of-code:
main: main.hs
source-dirs: src
ghc-options:
- -Wall
- -O2
- -threaded
- -rtsopts
- -with-rtsopts=-N
module Day01 (part1, part2) where
import ClassyPrelude
import Text.Read
part1, part2 :: [Text] -> Int
part1 = sum . map (fuel . (read :: String -> Int) . unpack)
part2 = sum . map (fuelRecursive . (read :: String -> Int) . unpack)
fuel :: Int -> Int
fuel = (max 0) . (subtract 2) . (`div` 3)
fuelRecursive :: Int -> Int
fuelRecursive 0 = 0
fuelRecursive mass = fuel mass + fuelRecursive (fuel mass)
import ClassyPrelude
import Day01
main :: IO ()
main = getArgs >>= \case
[day, part] -> do
input <- lines <$> (readFileUtf8 . unpack $ "input/day" <> day)
putStrLn $ case lookup (day, part) solutions of
Just f -> "Result " <> day <> "-" <> part <> ": " <> f input
Nothing -> "Incorrect arguments."
_ -> putStrLn "Incorrect arguments."
solutions :: [( (Text, Text), [Text] -> Text )]
solutions =
[ ( ("01", "1"), tshow . Day01.part1 )
, ( ("01", "2"), tshow . Day01.part2 )
]
resolver: lts-14.16
# This file was autogenerated by Stack.
# You should not edit this file by hand.
# For more information, please see the documentation at:
# https://docs.haskellstack.org/en/stable/lock_files
packages: []
snapshots:
- completed:
size: 524804
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/14/16.yaml
sha256: 4d1519a4372d051d47a5eae2241cf3fb54e113d7475f89707ddb6ec06add2888
original: lts-14.16
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment