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
(defun next-house (house i) | |
(destructuring-bind (x y) house | |
(case i | |
(#\> (list (+ x 1) y)) | |
(#\< (list (- x 1) y)) | |
(#\^ (list x (+ y 1))) | |
(t (list x (- y 1)))))) | |
(defun count-unique-deliveries-by-santa (file) | |
(with-open-file (stream file) |
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
(defun box-dimensions (box-string) | |
"Given the dimensions of a box as a string in the form 'XxYxZ', return a | |
sequence containing the dimensions as integers X, Y and Z, sorted in | |
ascending order." | |
(sort (mapcar #'parse-integer | |
(str:split "x" box-string)) | |
#'<)) | |
(defun paper-for-box (box) | |
"Given the dimensions of BOX as integers sorted in ascending order, return |
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
(defparameter *instruction->move* | |
'((#\( . 1+) | |
(#\) . 1-)) | |
"Map instructions to floor movements.") | |
(defun all-floors (instructions) | |
"Return a sequence of all floors passed through when starting at floor 0 and | |
following the list of INSTRUCTIONS." | |
(reverse (reduce #'(lambda (acc i) | |
(cons (funcall (cdr (assoc i *instruction->move*)) |
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
(ns blocks-world.core) | |
(def ^:private database | |
"The blocks database." | |
[[:b1 :shape :brick] | |
[:b1 :color :green] | |
[:b1 :size :small] | |
[:b1 :supported-by :b2] | |
[:b1 :supported-by :b3] | |
[:b2 :shape :brick] |
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
(ns robbie.core) | |
(def rooms | |
"Robbie's world." | |
{:living-room {:north :front-stairs | |
:south :dining-room | |
:east :kitchen} | |
:upstairs-bedroom {:west :library | |
:south :front-stairs} | |
:dining-room {:north :living-room |
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
(ns compare-descriptions.core | |
(:require [clojure.set :only intersection])) | |
(defn- right-side | |
"Given a list containing the descriptions of two objects separated by the | |
keyword :-vs-, return the description of the object to the right of the | |
separator." | |
[descriptions] | |
(rest (drop-while #(not= % :-vs-) | |
descriptions))) |
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
(ns day-1.core) | |
(def input (slurp "input.txt")) | |
(def up \() | |
(defn where-is-santa | |
"What floor will Santa finish on after following INSTRUCTIONS?" | |
[instructions] | |
(reduce #(+ %1 |
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
(ns day-2.core) | |
(defn box-dimensions | |
"Given the dimensions of a box in the form \"XxYxZ\", return a sorted | |
sequence of X, Y and Z." | |
[box] | |
(sort (map parse-long | |
(re-seq #"[0-9]+" box)))) | |
(def boxes |
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
(ns day-2.core | |
(:require [clojure.string :as str])) | |
(def rounds | |
"Return a sequence of all the rounds of the game." | |
(str/split (slurp "input.txt") | |
#"\n")) | |
(defn plan-a | |
[round] |
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
(ns day-1.core | |
(:require [clojure.string :as string])) | |
(defn- calories-per-elf | |
"The amount of calories each elf is carrying, greatest value first." | |
[input-file-name] | |
(sort > | |
(map #(reduce + | |
(map parse-long | |
(re-seq #"[0-9]+" %))) |
NewerOlder