|
|
@ -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. |
|
|
|