Last active
December 16, 2022 19:46
-
-
Save schmalz/d313015a9dd3380b60734ac30e5ee4b6 to your computer and use it in GitHub Desktop.
Advent of Code 2015 - day 2.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns day-2.core) | |
(defn box-dimensions | |
"Given the dimensions of a box in the form \"XxYxZ\", return a sorted | |
sequence of X, Y and Z." | |
[box] | |
(sort (map parse-long | |
(re-seq #"[0-9]+" box)))) | |
(def boxes | |
(map box-dimensions | |
(re-seq #"[0-9x]+" | |
(slurp "input.txt")))) | |
(defn paper-for-box | |
"The amount of paper required to wrap a box of dimensions X, Y and Z." | |
[[x y z]] | |
(+ (* 3 x y) | |
(* 2 x z) | |
(* 2 y z))) | |
(defn ribbon-for-box | |
"The amount of ribbon required to tie a box of dimensions X, Y and Z." | |
[[x y z]] | |
(+ (* 2 x) | |
(* 2 y) | |
(* x y z))) | |
(def paper-for-all-boxes | |
(reduce + | |
(map paper-for-box boxes))) | |
(def ribbon-for-all-boxes | |
(reduce + | |
(map ribbon-for-box boxes))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment