Commit ebb315de authored by Nicolas Lenz's avatar Nicolas Lenz

Use stack as build tool

parent 6d0510e2
cabal-version: 1.12
-- This file has been generated from package.yaml by hpack version 0.31.1.
--
-- see: https://github.com/sol/hpack
--
-- hash: ec04a239f02e42ba3551e0a7529c4268de82830c0633716ed9ffd4c2ff152247
name: advent-of-code
version: 0.0.0
synopsis: My solutions for the Advent of Code
description: Please see the README at <https://git.eisfunke.com/research/advent-of-code#readme>
category: Puzzle
author: Nicolas Lenz
maintainer: nicolas@eisfunke.com
copyright: 2018 Nicolas Lenz
license: MIT
license-file: LICENSE
build-type: Simple
extra-source-files:
README.md
source-repository head
type: git
location: https://git.eisfunke.com/research/advent-of-code
executable advent-of-code
main-is: Main.hs
other-modules:
Day01
Paths_advent_of_code
hs-source-dirs:
src
ghc-options: -O2 -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
default-language: Haskell2010
name: advent-of-code
version: 0.0.0
license: MIT
git: "https://git.eisfunke.com/research/advent-of-code"
author: "Nicolas Lenz"
maintainer: "nicolas@eisfunke.com"
copyright: "2018 Nicolas Lenz"
extra-source-files:
- README.md
synopsis: My solutions for the Advent of Code
category: Puzzle
description: Please see the README at <https://git.eisfunke.com/research/advent-of-code#readme>
dependencies:
- base >= 4.7 && < 5
executables:
advent-of-code:
main: Main.hs
source-dirs: src
ghc-options:
- -O2
- -threaded
- -rtsopts
- -with-rtsopts=-N
import System.Environment
module Day01 (part1, part2) where
main :: IO ()
main = do
args <- getArgs
case args of
["part1"] -> part1
["part2"] -> part2
_ -> putStrLn "gief part"
part1 :: [String] -> IO ()
part1 input = print $ last $ applySeq (toFunction <$> input) 0
part1 :: IO ()
part1 = do
freqChanges <- readFreqChanges
print $ last $ applySeq freqChanges 0
part2 :: [String] -> IO ()
part2 input = print $ firstTwice $ applySeq (cycle (toFunction <$> input)) 0
part2 :: IO ()
part2 = do
freqChanges <- readFreqChanges
print $ firstTwice $ applySeq (cycle freqChanges) 0
readFreqChanges :: IO [Integer -> Integer]
readFreqChanges = do
input <- readFile "01.input"
return (toFunction <$> lines input)
toFunction :: String -> (Integer -> Integer)
toFunction ('+':as) = (+(read as))
......
import System.Environment
import Day01
main :: IO ()
main = do
args <- getArgs
case args of
["01-1"] -> readFile "day01.input" >>= Day01.part1 . lines
["01-2"] -> readFile "day01.input" >>= Day01.part1 . lines
_ -> putStrLn "Example call: advent-of-code 01-1 for day 01, part 1\nInput should be named like day01.input."
resolver: lts-12.19
packages:
- .
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