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
(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 '*)) |
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 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)]) |
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 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? |
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
;golfed it | |
(apply * (map (comp count (fn [[t d]] (filter #(> (* (- t %) %) d) (range 1 t)))) {7 9 15 40 30 200})) |
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
(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)) |
OlderNewer