From 5335e6fb8d0be088fe05af4be46c16908a696b93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Depreeuw?= Date: Sun, 6 Dec 2020 17:10:24 +0100 Subject: [PATCH] Move day1 function to src/Day1.hs --- AdventOfCode2020.cabal | 4 +++- Main.hs | 11 +---------- src/Day1.hs | 10 +++++++++- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/AdventOfCode2020.cabal b/AdventOfCode2020.cabal index 1584ace..a70ba56 100644 --- a/AdventOfCode2020.cabal +++ b/AdventOfCode2020.cabal @@ -17,11 +17,13 @@ maintainer: gael@depreeuw.dev extra-source-files: CHANGELOG.md, README.md library - exposed-modules: Day1 + exposed-modules: Day1, Day2 -- other-modules: -- other-extensions: build-depends: base ^>=4.13.0.0 , containers ^>=0.6.4.1 + , text ^>=1.2.4.0 + , attoparsec ^>=0.13.2.4 hs-source-dirs: src default-language: Haskell2010 diff --git a/Main.hs b/Main.hs index d7ad0c9..25e0a3a 100644 --- a/Main.hs +++ b/Main.hs @@ -1,15 +1,6 @@ module Main where -import qualified Day1 (fixExpenseReport) - -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 - +import Day1 (day1) main :: IO () main = do diff --git a/src/Day1.hs b/src/Day1.hs index 973fc3c..7911468 100644 --- a/src/Day1.hs +++ b/src/Day1.hs @@ -1,4 +1,4 @@ -module Day1 (fixExpenseReport) where +module Day1 (day1) where import qualified Data.IntSet as DIS import Data.Maybe (mapMaybe) @@ -7,6 +7,14 @@ type Target = Int type Expenses = [Int] 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 -- number in the set to make it 2020. If found, return the multiplication of -- the two numbers.