Move day1 function to src/Day1.hs

pull/1/head
Gaël Depreeuw 4 years ago
parent 03759d2e79
commit 5335e6fb8d
Signed by: Mithror
GPG Key ID: 8AB218ABA4867F78
  1. 4
      AdventOfCode2020.cabal
  2. 11
      Main.hs
  3. 10
      src/Day1.hs

@ -17,11 +17,13 @@ maintainer: gael@depreeuw.dev
extra-source-files: CHANGELOG.md, README.md extra-source-files: CHANGELOG.md, README.md
library library
exposed-modules: Day1 exposed-modules: Day1, Day2
-- other-modules: -- other-modules:
-- other-extensions: -- other-extensions:
build-depends: base ^>=4.13.0.0 build-depends: base ^>=4.13.0.0
, containers ^>=0.6.4.1 , containers ^>=0.6.4.1
, text ^>=1.2.4.0
, attoparsec ^>=0.13.2.4
hs-source-dirs: src hs-source-dirs: src
default-language: Haskell2010 default-language: Haskell2010

@ -1,15 +1,6 @@
module Main where module Main where
import qualified Day1 (fixExpenseReport) import Day1 (day1)
day1 :: IO ()
day1 = do
r <- readFile "./input/day1"
putStr "[Day 1-1] fix: "
print . Day1.fixExpenseReport 2020 2 . fmap read . lines $ r
putStr "[Day 1-2] fix: "
print . Day1.fixExpenseReport 2020 3 . fmap read . lines $ r
main :: IO () main :: IO ()
main = do main = do

@ -1,4 +1,4 @@
module Day1 (fixExpenseReport) where module Day1 (day1) where
import qualified Data.IntSet as DIS import qualified Data.IntSet as DIS
import Data.Maybe (mapMaybe) import Data.Maybe (mapMaybe)
@ -7,6 +7,14 @@ type Target = Int
type Expenses = [Int] type Expenses = [Int]
type Expenses' = DIS.IntSet type Expenses' = DIS.IntSet
day1 :: IO ()
day1 = do
r <- readFile "./input/day1"
putStr "[Day 1-1] fix: "
print . fixExpenseReport 2020 2 . fmap read . lines $ r
putStr "[Day 1-2] fix: "
print . fixExpenseReport 2020 3 . fmap read . lines $ r
-- Turn the list into an IntSet. For each element in the set, look up the -- Turn the list into an IntSet. For each element in the set, look up the
-- number in the set to make it 2020. If found, return the multiplication of -- number in the set to make it 2020. If found, return the multiplication of
-- the two numbers. -- the two numbers.

Loading…
Cancel
Save