Skip to content

Instantly share code, notes, and snippets.

@schmalz
Last active December 16, 2022 19:46
Show Gist options
  • Save schmalz/d313015a9dd3380b60734ac30e5ee4b6 to your computer and use it in GitHub Desktop.
Save schmalz/d313015a9dd3380b60734ac30e5ee4b6 to your computer and use it in GitHub Desktop.
Advent of Code 2015 - day 2.
(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