2015 Day 02 in Haskell
This commit is contained in:
parent
6e4b95af18
commit
6ca8baf1b5
16
2015/day02/day02.hs
Normal file
16
2015/day02/day02.hs
Normal file
@ -0,0 +1,16 @@
|
||||
import Aoc
|
||||
import Data.List.Split
|
||||
|
||||
parseFile :: [String] -> [(Int, Int, Int)]
|
||||
parseFile = map $ triplet . map read . splitOn "x"
|
||||
|
||||
part1 :: [(Int, Int, Int)] -> Int
|
||||
part1 = sum . map wrapping
|
||||
where wrapping (l, w, h) = let areas = [l*w, l*h, w*h] in 2*sum areas + minimum areas
|
||||
|
||||
part2 :: [(Int, Int, Int)] -> Int
|
||||
part2 = sum . map wrapping
|
||||
where wrapping (l, w, h) = 2*minimum [l+w, l+h, w+h] + l*w*h
|
||||
|
||||
main :: IO ()
|
||||
main = aocMain parseFile part1 part2
|
11
aoc.hs
11
aoc.hs
@ -9,4 +9,13 @@ aocMain parseFile part1 part2 = do
|
||||
print $ "Part 2: " ++ show (part2 input)
|
||||
|
||||
enumerate :: [a] -> [(Int, a)]
|
||||
enumerate xs = zip [0..length xs] xs
|
||||
enumerate xs = zip [0..length xs] xs
|
||||
|
||||
unimplemented :: Show p => p -> Int
|
||||
unimplemented = error . show
|
||||
|
||||
pair :: [a] -> (a, a)
|
||||
pair as = let [a1, a2] = as in (a1, a2)
|
||||
|
||||
triplet :: [a] -> (a, a, a)
|
||||
triplet as = let [a1, a2, a3] = as in (a1, a2, a3)
|
Loading…
Reference in New Issue
Block a user