solve: day 1, part 2
This commit is contained in:
parent
dfe5935b5e
commit
f88701078a
2 changed files with 44 additions and 0 deletions
|
@ -1 +1,21 @@
|
||||||
# Day 1
|
# Day 1
|
||||||
|
|
||||||
|
## Part 1
|
||||||
|
|
||||||
|
Took some time to remember how to read input.
|
||||||
|
|
||||||
|
I assumed that I could build the list of pairs from
|
||||||
|
the start and never tracing back (order doesn't matter).
|
||||||
|
|
||||||
|
## Part 2
|
||||||
|
|
||||||
|
Have to take the previous solution and deal with combinations of three values.
|
||||||
|
|
||||||
|
Hardest part is figuring out how to take a list of numbers and return a list
|
||||||
|
of 3 tuples for the combinations of pairs:
|
||||||
|
|
||||||
|
```hs
|
||||||
|
triples xs = sequence $ replicate 3 xs
|
||||||
|
```
|
||||||
|
|
||||||
|
This produces some additional data but I assume these entries won't be false positives.
|
||||||
|
|
24
2020/01/part2.hs
Executable file
24
2020/01/part2.hs
Executable file
|
@ -0,0 +1,24 @@
|
||||||
|
#!/usr/bin/env runghc
|
||||||
|
|
||||||
|
import Data.List
|
||||||
|
import Data.Maybe
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main =
|
||||||
|
do
|
||||||
|
input <- getInput
|
||||||
|
|
||||||
|
let answer = product $ fromJust $ find isSolutionTriple $ triples input
|
||||||
|
|
||||||
|
putStrLn $ show answer
|
||||||
|
|
||||||
|
getInput :: IO [Int]
|
||||||
|
getInput = fmap (map read . lines) getContents
|
||||||
|
|
||||||
|
triples :: [a] -> [[a]]
|
||||||
|
triples xs = sequence $ replicate 3 xs
|
||||||
|
|
||||||
|
isSolutionTriple :: [Int] -> Bool
|
||||||
|
isSolutionTriple triple = sum triple == 2020
|
||||||
|
|
||||||
|
multplyTriple (a, b, c) = a * b * c
|
Loading…
Reference in a new issue