Safe HaskellNone

Day01

Description

General - List combination/search problem. Build all combinations of list elements. And look for the one that sums up to be 2020.

Given that + is commutative, we only need to build [(1,2), (1,3), (2,3)] out of [1, 2, 3]. And we can stop looking as soon as we find the first tuple that satisfies the condition (making the evaluation of the list (of tuples) lazy (build only the part of the list you need to find the first matching tuple) is another optimisation to consider).

Another nice variation on the challenge would be to think about how to implement combinationsN. But that is for another day ...

Part 1 - Do it with pairs.

Part 2 - Do it with triplets.

Synopsis

Documentation

type Expense = Int #

input :: String -> [Expense] #

Read the input file.

combinations2 :: [a] -> [(a, a)] #

Returns combinations of pairs.

combinations3 :: [a] -> [(a, a, a)] #

Returns combinations of triplets.

part1 :: [Expense] -> Int #

Solve part1.

part2 :: [Expense] -> Int #

Solve part2.