Skip to content

Instantly share code, notes, and snippets.

@sbenhaim
Last active December 16, 2015 02:54
Show Gist options
  • Save sbenhaim/a81ed547a6fdeacf1f42 to your computer and use it in GitHub Desktop.
Save sbenhaim/a81ed547a6fdeacf1f42 to your computer and use it in GitHub Desktop.
Advent of Code: 2
(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