Skip to content

Instantly share code, notes, and snippets.

@underhilllabs
Last active December 2, 2015 19:17
Show Gist options
  • Save underhilllabs/d69743201afc522705dd to your computer and use it in GitHub Desktop.
Save underhilllabs/d69743201afc522705dd to your computer and use it in GitHub Desktop.
(use 'clojure.java.io)
(def ribbon (atom 0))
(def paper (atom 0))
(with-open [rdr (reader "./presents.txt")]
(doseq [line (line-seq rdr)]
(let [all (clojure.string/split line #"x")
w (. Integer parseInt (first all))
h (. Integer parseInt (second all))
l (. Integer parseInt (nth all 2))
side1 (* w h)
side2 (* w l)
side3 (* h l)
area (* w h l)
surface-area (* 2 (+ side1 side2 side3))
min-side (min side1 side2 side3)
paper-for-box (+ min-side surface-area)
min-circ (* 2 (min (+ w h)
(+ w l)
(+ h l)))
ribbon-for-box (+ area min-circ)]
(swap! paper + paper-for-box)
(swap! ribbon + ribbon-for-box))))
(printf "ribbon is %s%n" @ribbon)
(printf "paper yardage is %s%n " @paper)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment