Last active
December 16, 2015 02:54
-
-
Save sbenhaim/a81ed547a6fdeacf1f42 to your computer and use it in GitHub Desktop.
Advent of Code: 2
This file contains 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 advent.a2 | |
(:require [clojure.string :as str])) | |
(defn parse-int [s] | |
(Integer/parseInt s)) | |
(let [text (slurp "a2.txt")] | |
(reduce + (for [line (str/split-lines text)] | |
(let [[l w h] (str/split line #"x") | |
[l w h] (map #(Integer/parseInt %) [l w h]) | |
areas [(* l w) (* w h) (* l h)] | |
slack (apply min areas) | |
area (apply + slack (map #(* 2 %) areas))] | |
area)))) | |
(let [text (slurp "a2.txt")] | |
(reduce + (for [line (str/split-lines text)] | |
(let [lwh (str/split line #"x") | |
lwh (map #(Integer/parseInt %) lwh) | |
dim (take 2 (sort lwh)) | |
area (* 2 (apply + dim)) | |
vol (reduce * lwh)] | |
(+ area vol))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment