Skip to content

Instantly share code, notes, and snippets.

# Classic
## Simplest and popular
* 15.0g Coffee (one scoop, espresso grind)
* 10s Pour water 60.0g at 80.0°C
* 21s Stir (fast)
* 16s Steep
* 15s Plunge
(ns advent.a16
(:require [clojure.string :as str]))
(def sue
{:children 3
:cats 7
:samoyeds 2
:pomeranians 3
:akitas 0
(ns advent.a15
(:require
[clojure.string :as str]
[clojure.core.logic :as l :refer [run run* fresh]]
[clojure.core.logic.fd :as fd]))
(def text "Sugar: capacity 3, durability 0, flavor 0, texture -3, calories 2
Sprinkles: capacity -3, durability 3, flavOr 0, texture 0, calories 9
Candy: capacity -1, durability 0, flavor 4, texture 0, calories 1
Chocolate: capacity 0, durability 0, flavor -2, texture 2, calories 8")
(ns advent.a14
(:require [clojure.string :as str]))
(def rules "Rudolph can fly 22 km/s for 8 seconds, but then must rest for 165 seconds.
Cupid can fly 8 km/s for 17 seconds, but then must rest for 114 seconds.
Prancer can fly 18 km/s for 6 seconds, but then must rest for 103 seconds.
Donner can fly 25 km/s for 6 seconds, but then must rest for 145 seconds.
Dasher can fly 11 km/s for 12 seconds, but then must rest for 125 seconds.
Comet can fly 21 km/s for 6 seconds, but then must rest for 121 seconds.
Blitzen can fly 18 km/s for 3 seconds, but then must rest for 50 seconds.
(ns advent.a13
(:require [clojure.string :as str]
[clojure.math.combinatorics :refer [permutations]]))
(defn parse [l]
(let [[_ subject sign value object]
(re-find #"(\w+) would (gain|lose) (\d+) happiness units by sitting next to (\w+)." l)]
[subject
object
(Integer/parseInt
(ns advent.a10)
(defn look-and-say [ls]
(flatten (for [l (partition-by identity ls)]
[(count l) (first l)])))
(defn str->ints [s]
(map #(Integer/parseInt (str %)) s))
(time
(ns advent.a9
(:require [clojure.string :as str]
[clojure.math.combinatorics :refer [permutations]]))
(def text "AlphaCentauri to Snowdin = 66
AlphaCentauri to Tambi = 28
AlphaCentauri to Faerun = 60
AlphaCentauri to Norrath = 34
AlphaCentauri to Straylight = 34
AlphaCentauri to Tristram = 3
(ns a6
(:require [clojure.string :as str]))
(set! *warn-on-reflection* true)
(set! *unchecked-math* :warn-on-boxed)
(defn parse-int [s]
(Integer/parseInt s))
(defn get-coords [^long n [^long sx ^long sy] [^long ex ^long ey]]
(ns advent.a8
(:require [clojure.string :as str]
[instaparse.core :as insta]))
(def parser (insta/parser (slurp "a8.bnf")))
(def lines (str/split-lines (slurp "a8.txt")))
(defn nlits [l] (count (re-seq #"[^\s]" l)))
(ns advent.a7
(:require [clojure.string :as str]
[instaparse.core :as insta]
[clojure.core.match :refer [match]]))
(def MAX (int (dec (Math/pow 2 16))))
(defn unsign [i]
(cond (< i 0) (+ MAX (inc i))
(> i MAX) (- (dec i) MAX)