diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2024-11-01 00:49:17 +0000 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2024-11-01 00:49:17 +0000 |
commit | 5954e0f299f0b412e377d9f9eaac34a2230a0a7e (patch) | |
tree | 97b7e86c4f21db4d6461bd4fe0aed4c98cbc2687 | |
parent | 8c6c652c691c3b6a7e1fd37afb4f80a6c6b58b9a (diff) | |
download | advent-of-code-5954e0f299f0b412e377d9f9eaac34a2230a0a7e.tar.gz advent-of-code-5954e0f299f0b412e377d9f9eaac34a2230a0a7e.tar.bz2 advent-of-code-5954e0f299f0b412e377d9f9eaac34a2230a0a7e.zip |
Puzzle 2 2015 done
-rw-r--r-- | 2015/puzzle-2.hs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/2015/puzzle-2.hs b/2015/puzzle-2.hs new file mode 100644 index 0000000..3fbbd65 --- /dev/null +++ b/2015/puzzle-2.hs @@ -0,0 +1,28 @@ +import qualified Data.Text as DT +import qualified Data.List as DL + +parse_line s = map read_int members + where + delim = DT.pack "x" + content = DT.pack s + members = map DT.unpack $ DT.splitOn delim content + read_int = \x -> (read x) :: Int + +surface_area [l, w, h] = (2 * l * w) + (2 * w * h) + (2 * l * h) +extra_area xs = x * y + where [x, y] = take 2 $ DL.sort xs +total_area xs = (surface_area xs) + (extra_area xs) + +volume [l, w, h] = l * w * h +ribbon_wrap xs = (2 * x) + (2 * y) + where [x, y] = take 2 $ DL.sort xs + +total_ribbon xs = (volume xs) + (ribbon_wrap xs) + +main = do + content <- readFile "2-input" + let dimensions = map parse_line $ lines content + let areas = sum $ map total_area dimensions + let ribbon = sum $ map total_ribbon dimensions + putStrLn $ "Round 1: " ++ (show areas) + putStrLn $ "Round 2: " ++ (show ribbon) |