init 2015
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
(ns day01
|
||||
(:require input-manager))
|
||||
|
||||
(def input (input-manager/get-input-raw 2015 01))
|
||||
|
||||
(def up? #{\(})
|
||||
(def down? #{\)})
|
||||
|
||||
;; part 1
|
||||
(-
|
||||
(count (filter up? input))
|
||||
(count (filter down? input)))
|
||||
|
||||
;; part 2
|
||||
(loop [i 0
|
||||
floor 0]
|
||||
(cond
|
||||
(< floor 0) i
|
||||
|
||||
(up? (.charAt input i))
|
||||
(recur (inc i)
|
||||
(inc floor))
|
||||
|
||||
:else
|
||||
(recur (inc i)
|
||||
(dec floor))))
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
(ns day02
|
||||
(:require [input-manager]))
|
||||
|
||||
(defn parse-line
|
||||
"s is a string in the form of lxwxh, whee l, w, and h are integral patterns"
|
||||
[s]
|
||||
(map parse-long (re-seq #"\d+" s)))
|
||||
|
||||
(def input (->> (input-manager/get-input 2015 2)
|
||||
(map parse-line)))
|
||||
|
||||
(defn smallest-side [[l w h]]
|
||||
(min (* l w)
|
||||
(* h w)
|
||||
(* l h)))
|
||||
|
||||
(defn paper-needed [[l w h :as args]]
|
||||
(+ (* 2 (+ (* l w) (* w h) (* h l)))
|
||||
(smallest-side args)))
|
||||
|
||||
;; part 1
|
||||
(->> input
|
||||
(map paper-needed)
|
||||
(apply +))
|
||||
|
||||
(defn smallest-perimeter [[l w h]]
|
||||
(* 2 (min (+ l w)
|
||||
(+ h w)
|
||||
(+ l h))))
|
||||
|
||||
(defn volume [[l w h]]
|
||||
(* l w h))
|
||||
|
||||
;; part 2
|
||||
(->> input
|
||||
(map (juxt smallest-perimeter volume))
|
||||
(map #(apply + %))
|
||||
(apply +))
|
||||
@@ -0,0 +1,26 @@
|
||||
(ns day03
|
||||
(:require [input-manager]
|
||||
[clojure.set]))
|
||||
|
||||
(def input (input-manager/get-input-raw 2015 3))
|
||||
|
||||
(defn get-houses [input]
|
||||
(->> input
|
||||
(reduce (fn [[[x y] visited]
|
||||
el]
|
||||
(let [pos' (condp = el
|
||||
\> [(inc x) y]
|
||||
\< [(dec x) y]
|
||||
\^ [x (inc y)]
|
||||
\v [x (dec y)])]
|
||||
[pos' (conj visited pos')]))
|
||||
[[0 0] #{}])
|
||||
second))
|
||||
|
||||
;; part 1
|
||||
(count (get-houses input))
|
||||
|
||||
;; part 2
|
||||
(count (clojure.set/union (get-houses (take-nth 2 input))
|
||||
(get-houses (take-nth 2 (rest input)))))
|
||||
|
||||
Reference in New Issue
Block a user