Skip to content

Instantly share code, notes, and snippets.

@joinr
joinr / day23.clj
Created January 14, 2023 04:01
opt on day23
(load-file "aoc.clj")
(ns day23
(:require aoc
[clojure.data.int-map :refer [dense-int-set int-map]]))
(set! *unchecked-math* :warn-on-boxed)
(def ^:const S 256)
(def ^:const N (- S))
@joinr
joinr / v2.clj
Created January 12, 2023 18:30
minor mods to optimize some aoc submissions
(ns day19
(:require aoc))
(set! *warn-on-reflection* true)
(set! *unchecked-math* :warn-on-boxed)
(defrecord Blueprint [prices max-resources])
(defn line->blueprint [line]
(let [[_ ore-ore clay-ore obs-ore obs-clay geode-ore geode-obs] line
@joinr
joinr / full.clj
Last active December 12, 2022 16:07
minor optimizations for poster's code for aoc2022 8b
(ns aoc-2022.day08
(:require
[clojure.java.io :as io]
[criterium.core :as c]))
(set! *unchecked-math* :warn-on-boxed)
(defn- line->cells [line]
(vec (map (fn [h] {:height (read-string (str h))}) line)))
@joinr
joinr / diff.clj
Last active December 8, 2022 21:29
exploration of the fastest way to compute diff using the tech stack.
;;https://www.reddit.com/r/Clojure/comments/zd36cb/faster_way_to_calculate_difference_of_vector/
(set! *unchecked-math* :warn-on-boxed)
(set! *warn-on-reflection* true)
(require '[tech.v3.dataset :as ds])
(require '[tech.v3.datatype :as dtype])
(require '[tech.v3.datatype.functional :as func])
(require '[criterium.core :as c])
@joinr
joinr / discussion.md
Created November 30, 2022 21:10
discussion on deps vs lein

There is quite the thread on clojureverse where a lot of this is hashed out (both advocates and critics).

I think the historical motivation is well captured in Alex Miller's talk A Trick of the Tool. It primarily focuses on the emergence of tools.build.
From the QA section "The Beast of Obstacle":

"We really spent a long time chasing a declarative way to define builds, and the attributes that you use in your builds, and get that into declarative data, and deps.edn...we came at it from several different directions, I build things that worked several different ways, and we eventually threw it all in the bin...and decided that...it's very tempting to take [the] common build scenario like compile stuff, make a jar, that's it, where there's only like 3 variable things in there, and I can pull them out and put them in attributes like declaratively drive some set

@joinr
joinr / clone-bench.cljs
Last active November 30, 2022 06:49
clone bench
(defn clone-assoc [obj k v]
(let [m (Object.assign #js{} obj)]
(aset m k v)
m))
;;cljs.user> (def origin #js{"x" 1})
;;#'cljs.user/origin
;;cljs.user> (clone-assoc origin "x" 2)
;;#js {:x 2}
;;cljs.user> origin
@joinr
joinr / parsed.clj
Created November 24, 2022 17:22
xml parsed output pretty printed
{:tag :xmlns.http%3A%2F%2Fwww.w3.org%2F2005%2FAtom/feed,
:attrs
#:xmlns.http%3A%2F%2Fwww.w3.org%2FXML%2F1998%2Fnamespace{:base
"https://home.treasury.gov/resource-center/data-chart-center/interest-rates/pages/xml"},
:content
({:tag :xmlns.http%3A%2F%2Fwww.w3.org%2F2005%2FAtom/title,
:attrs {:type "text"},
:content ("DailyTreasuryYieldCurveRateData")}
{:tag :xmlns.http%3A%2F%2Fwww.w3.org%2F2005%2FAtom/id,
:attrs {},
@joinr
joinr / puzzle.clj
Last active December 30, 2022 14:32
Using core.logic to solve a puzzle in a game
(ns puzzle
(:require [clojure.core.logic :as l]))
;; At the dinner party were Lady Winslow, Doctor Marcolla, Countess Contee, Madam
;; Natsiou, and Baroness Finch.
;; The women sat in a row. They all wore different colors and [Doctor Marcolla] wore a
;; jaunty [white] hat. [Natsiou] was at the far left, next to the guest wearing
;; a [red] jacket. The lady in [blue] sat left of someone in [purple]. I remember
;; that [blue] outfit because the woman spilled her [rum] all over it. The
;; traveler from [dabrovka] was dressed entirely in [green]. When one of the dinner
@joinr
joinr / demo.clj
Created October 20, 2022 06:38
Fancy derive types for clojure
(ns demo
(:require [fancyclass :as fancy :refer [derives?]]))
(defprotocol SomeParentType)
(fancy/derived-type CustomMap [SomeParentType :base/map :arbitrary/tag])
;; demo> (def m (->CustomMap :name "Bilbo" :occupation "Burglar"))
;; #'demo/m
;; demo> m
;; {:occupation "Burglar", :name "Bilbo"}
(ns util
(:refer-clojure :exclude [pmap])
(:require [clojure.core.async :as async]))
(defn chan? [x]
(instance? clojure.core.async.impl.channels.ManyToManyChannel x))
(defn guess-physical-cores
"Hueristic used to account for likely prevalent
hyperthreading influencing the supposed available