pull/1/head
Gaël Depreeuw 5 years ago
parent 7464063120
commit 94c032e9da
  1. 2
      .gitignore
  2. 3
      ChangeLog.md
  3. 2
      Setup.hs
  4. 17
      app/Main.hs
  5. 100
      app/input_day1
  6. 48
      package.yaml
  7. 20
      src/Day1.hs
  8. 66
      stack.yaml
  9. 2
      test/Spec.hs

2
.gitignore vendored

@ -20,3 +20,5 @@ cabal.project.local
cabal.project.local~ cabal.project.local~
.HTF/ .HTF/
.ghc.environment.* .ghc.environment.*
AdventOfCode2019.cabal
stack.yaml.lock

@ -0,0 +1,3 @@
# Changelog for AdventOfCode2019
## Unreleased changes

@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain

@ -0,0 +1,17 @@
module Main where
import Day1
import System.IO
day1_fuel :: String -> [Fuel]
day1_fuel = fmap (calculateFuel . read) . lines
main :: IO ()
main = do
r <- readFile "./app/input_day1"
putStr "[Day 1-1] Fuel needed: "
let fs = day1_fuel r
print $ sum fs
putStr "[Day 1-2] Fuel needed: "
print (sum fs + (sum . fmap calculateFuelOfFuel) fs)

@ -0,0 +1,100 @@
128167
65779
88190
144176
109054
70471
113510
81741
65270
111217
51707
81122
142720
65164
85045
85776
51332
110021
99706
50512
95429
149220
102777
93907
61769
66946
121583
132351
53809
73261
122964
120792
73998
79590
140881
53130
82498
72725
127422
143777
55787
95454
88293
107988
145145
59562
142929
132977
88825
104657
70644
124614
66443
117825
97016
79578
136114
64975
113838
63294
58466
76827
56288
126977
63815
129398
123017
118773
144464
60620
79084
94685
70854
148054
134179
113832
113742
115771
115543
73241
62914
146134
128066
52002
132377
100765
105048
59936
131324
137384
139352
127350
116249
79847
53530
99738
61969
118730
121980
72977

@ -0,0 +1,48 @@
name: AdventOfCode2019
version: 0.1.0.0
github: "githubuser/AdventOfCode2019"
license: BSD3
author: "Author name here"
maintainer: "example@example.com"
copyright: "2019 Author name here"
extra-source-files:
- README.md
- ChangeLog.md
# Metadata used when publishing your package
# synopsis: Short description of your package
# category: Web
# To avoid duplicated efforts in documentation and dealing with the
# complications of embedding Haddock markup inside cabal files, it is
# common to point users to the README.md file.
description: Please see the README on GitHub at <https://github.com/githubuser/AdventOfCode2019#readme>
dependencies:
- base >= 4.7 && < 5
library:
source-dirs: src
executables:
AdventOfCode2019-exe:
main: Main.hs
source-dirs: app
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- AdventOfCode2019
tests:
AdventOfCode2019-test:
main: Spec.hs
source-dirs: test
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- AdventOfCode2019

@ -0,0 +1,20 @@
module Day1
( calculateFuel
, calculateFuelOfFuel
, Mass
, Fuel
) where
type Mass = Integer
type Fuel = Integer
calculateFuel :: Mass -> Fuel
calculateFuel m =
let m' = subtract 2 (div m 3) in
if m' < 0 then 0 else m'
calculateFuelOfFuel :: Fuel -> Fuel
calculateFuelOfFuel f = go f 0
where go finput ftotal
| finput <= 0 = ftotal
| otherwise = go (calculateFuel finput) (ftotal + calculateFuel finput)

@ -0,0 +1,66 @@
# This file was automatically generated by 'stack init'
#
# Some commonly used options have been documented as comments in this file.
# For advanced use and comprehensive documentation of the format, please see:
# https://docs.haskellstack.org/en/stable/yaml_configuration/
# Resolver to choose a 'specific' stackage snapshot or a compiler version.
# A snapshot resolver dictates the compiler version and the set of packages
# to be used for project dependencies. For example:
#
# resolver: lts-3.5
# resolver: nightly-2015-09-21
# resolver: ghc-7.10.2
#
# The location of a snapshot can be provided as a file or url. Stack assumes
# a snapshot provided as a file might change, whereas a url resource does not.
#
# resolver: ./custom-snapshot.yaml
# resolver: https://example.com/snapshots/2018-01-01.yaml
resolver: lts-14.16
# User packages to be built.
# Various formats can be used as shown in the example below.
#
# packages:
# - some-directory
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
# subdirs:
# - auto-update
# - wai
packages:
- .
# Dependency packages to be pulled from upstream that are not in the resolver.
# These entries can reference officially published versions as well as
# forks / in-progress versions pinned to a git hash. For example:
#
# extra-deps:
# - acme-missiles-0.3
# - git: https://github.com/commercialhaskell/stack.git
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
#
# extra-deps: []
# Override default flag values for local packages and extra-deps
# flags: {}
# Extra package databases containing global packages
# extra-package-dbs: []
# Control whether we use the GHC we find on the path
# system-ghc: true
#
# Require a specific version of stack, using version ranges
# require-stack-version: -any # Default
# require-stack-version: ">=2.1"
#
# Override the architecture used by stack, especially useful on Windows
# arch: i386
# arch: x86_64
#
# Extra directories used by stack for building
# extra-include-dirs: [/path/to/dir]
# extra-lib-dirs: [/path/to/dir]
#
# Allow a newer minor version of GHC than the snapshot specifies
# compiler-check: newer-minor

@ -0,0 +1,2 @@
main :: IO ()
main = putStrLn "Test suite not yet implemented"
Loading…
Cancel
Save