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- lookup-edge [edges label] | |
(get edges label (edges :default))) | |
(defn- merge-nfa-edges [& edge-maps] | |
(into {} | |
(for [label (set (mapcat keys edge-maps))] | |
[label (apply union | |
(for [edges edge-maps] | |
(or (lookup-edge edges label) #{})))]))) |
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 macroexpand-n [n form] | |
(if (zero? n) | |
form | |
(recur (dec n) | |
(macroexpand-1 form)))) |
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
Host nfsn | |
Hostname ssh.phx.nearlyfreespeech.net | |
Host * | |
IdentityFile ~/.ssh/id_fibonatch_auto | |
IdentityFile ~/.ssh/id_fibonatch_weak |
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
(frequencies (for [obj (map (comp coerce-date :created-at) coll)] | |
(clojure.string/join "/" ((juxt year month) obj)))) |
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
;; this works fine | |
(defn- first-truthy-fn* [[preds & more-preds] args] | |
(when pred | |
(if (apply pred args) pred (recur more-preds args)))) | |
(defn first-truthy-fn | |
"Returns the first function in a seq of functions | |
that evaluates to truthy for the given arguments - | |
this shortciruits, only evaluating the functions |
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 shuffle.core | |
(:use (incanter core charts))) | |
; naive, O(n+m) | |
(defn take-rand1 [n coll] (take n (shuffle coll))) | |
; lazy, O(n!@#$%m^&) | |
(defn take-rand2 [n coll] | |
(let [coll (vec coll)] | |
(take n (distinct (repeatedly #(rand-nth coll)))))) |
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
;; amalloy's solution to Love Triangle | |
;; https://4clojure.com/problem/127 | |
(fn [m t e c i a r v g] | |
(let [p (t #(<= % (m g)) | |
(i #(* 2 %) 1)) | |
H (c g) | |
W (c p) | |
g (v (for [y g] | |
(v |
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
;; amalloy's solution to Tree reparenting | |
;; https://4clojure.com/problem/130 | |
(fn [new-root tree] | |
(let [connections ((fn links [tree] | |
(when-let [[root & children] (seq tree)] | |
(let [child-links (apply merge {} (map links children)) | |
conj (fnil conj [])] | |
(reduce (fn [m [child]] | |
(-> m |
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
;; amalloy's solution to Simple closures | |
;; https://4clojure.com/problem/107 | |
{0 {2 1} | |
1 {2 2} | |
2 {2 4, 16 256} | |
3 {1 1, 2 8, 3 27, 4 64} | |
4 {2 16} | |
8 {2 256}} |
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 primes "Generates an (infinite, lazy) sequence of primes" | |
[] | |
(letfn [(reinsert [table x prime] | |
(let [key (+ prime x)] | |
(update-in table key conj prime))) | |
(primes-step [table d] | |
(if-let [factors (get table d)] | |
(let [new-table (dissoc table d)] | |
(recur (reduce #(reinsert %1 d %2) | |
new-table |