Skip to content

Instantly share code, notes, and snippets.

View buntine's full-sized avatar
💭
Gringo Starr

Andrew Buntine buntine

💭
Gringo Starr
View GitHub Profile
@buntine
buntine / infix.clj
Created August 27, 2018 01:06
Clojure for the Brave and True - Chapter 7 infix to prefix notation function
(defn expr-arrange [op]
(fn arrange [expr]
(cond
(<= (count expr) 2) expr
(= (second expr) op)
(conj (arrange (drop 3 expr))
(list (second expr) (first expr) (nth expr 2)))
:else (conj (arrange (rest expr)) (first expr)))))
(def multiply (expr-arrange '*))
(ns advent-of-code-2023.core
(:require [clojure.string :refer [split split-lines]]))
(defn parse-line [game]
(let [[game-number plays] (split game #":\s")
play-seq (split plays #"[;,]\s")]
[(Integer. (re-find #"\d+" game-number))
(map #(let [[n color] (split % #"\s")]
[(Integer. n)
(keyword color)])
@buntine
buntine / advent-of-code-2023-day3.clj
Last active December 3, 2023 10:58
advent-of-code-2023-day3.clj
(ns advent-of-code-2023.day3)
(defn numbers [s]
(loop [m (re-matcher #"(?m)\d+" s)
res {}]
(if (.find m)
(recur m (assoc res [(.start m) (.end m)] (Integer. (.group m))))
res)))
(defn is-part?
@buntine
buntine / advent-of-code-2023-day6.clj
Last active December 6, 2023 12:40
advent-of-code-2023-day6.clj
;golfed it
(apply * (map (comp count (fn [[t d]] (filter #(> (* (- t %) %) d) (range 1 t)))) {7 9 15 40 30 200}))
@buntine
buntine / advent-of-code-2023-day8-cleaner.clj
Last active December 8, 2023 23:45
advent-of-code-2023-day8.clj
(defn path-follower [[dir & rest-dirs] graph edge]
(let [next-edge ((edge graph) ({:L 0 :R 1} dir))]
(->> (path-follower rest-dirs graph next-edge)
(cons edge)
lazy-seq)))
(defn steps [path graph start-edge goal]
(->> (path-follower (cycle path) graph start-edge)
(take-while #(not= % goal))
count))