day01: prettier solution
This commit is contained in:
parent
ca044c956a
commit
36ccd6f974
@ -1,11 +1,13 @@
|
||||
import Control.Arrow
|
||||
import Control.Monad
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
input <- map read . lines <$> readFile "input"
|
||||
print (day1a input)
|
||||
print (day1b input)
|
||||
input <- map read . lines <$> readFile "input"
|
||||
print $ day1 input 2
|
||||
print $ day1 input 3
|
||||
|
||||
day1a :: [Int] -> Int
|
||||
day1a input = head [x * y | x<-input, y<-input, x+y==2020]
|
||||
|
||||
day1b :: [Int] -> Int
|
||||
day1b input = head [x * y * z | x<-input, y<-input, z<-input, x+y+z==2020]
|
||||
day1 :: [Int] -> Int -> Int
|
||||
day1 input n =
|
||||
snd . head . filter ((== 2020) . fst) $
|
||||
map (sum &&& product) $ replicateM n input
|
||||
|
Loading…
Reference in New Issue
Block a user