Last active
December 2, 2015 19:17
-
-
Save underhilllabs/d69743201afc522705dd to your computer and use it in GitHub Desktop.
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
(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