This file contains 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
;; simple stats computed using xforms transducers | |
=> (require '[net.cgrand.xforms :as x]) | |
=> (into {} | |
(x/by-key #(> % 0.5) | |
(x/transjuxt {:min x/min :max x/max :avg x/avg :sd x/sd})) | |
(repeatedly 1e6 rand)) | |
{false | |
{:min 1.0036018363024368E-6, | |
:max 0.4999987525112054, | |
:avg 0.2502046186242099, |
This file contains 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
;; not quite an apple-to-apple comparison (merge3 and into) but the order of magnitude is correct: | |
;; into: 5µs | |
;; merge3: 17ns (yes, ns not µs) | |
;; | |
;; this huge difference comes from the fact that merge3 runtime varies with the number of modified keys (here 1) | |
;; while into runtime varies with the number of keys. | |
user=> (def e clojure.lang.PersistentHashMapKVMono/EMPTY) | |
(defn merge3 [anc a b fix] (clojure.lang.PersistentHashMapKVMono/merge anc a b fix)) | |
#'user/e |
This file contains 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 branch | |
"A recursive branching tree structure with half-cylinder flowers." | |
[level] | |
(if (= 0 level) | |
[(length 1.5) cylinder] | |
[(angle (fn [_] (m/random 3 5))) ry- | |
(length (fn [t] (* (m/random 0.75 1.5) (or (:last-length t) 1.5)))) | |
(map (fn [[a b]] (concat (take 8 (cycle [a b])) (branch (dec level)))) | |
[[ry line] [ry- line] [rx line] [rx- line]])])) |
This file contains 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
;; pagerank in podwerkeg | |
(reduce (fn [ranks _] | |
(keg/rdd (keg/join links ranks) | |
(x/for [[page-id [page-links rank]] % | |
dest page-links] | |
[dest (/ rank (count page-links))]) | |
(keg/by-key (x/reduce +) (map #(+ 0.15 (* 0.85 %)))))) | |
(keg/rdd links (keg/by-key (map (constantly 1)))) (range 10)) |
This file contains 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
;; Tetrahedron intersection based on this paper & algorithm: | |
;; http://vcg.isti.cnr.it/Publications/2003/GPR03/fast_tetrahedron_tetrahedron_overlap_algorithm.pdf | |
;; | |
;; Unlike original algorithm this implementation produces correct | |
;; results regardless of the orientation/ordering of points defining | |
;; the two tetrahedra. This is achieved via the orient-tetra function, | |
;; which ensures the correct ordering of vertices for this algorithm | |
;; to function properly. | |
;; | |
;; Implementation extracted from upcoming geometry library |
This file contains 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
;; Clojure 1.5.1 | |
=> ; coll (fn [f acc]) renvoie (reduce f acc coll) | |
=> ; coll (fn [f init]) renvoie (reduce f init coll) | |
=> (defn fnil [f init] init) | |
WARNING: fnil already refers to: #'clojure.core/fnil in namespace: cljug.core, being replaced by: #'cljug.core/fnil | |
#'cljug.core/fnil | |
=> (reduce + 0 nil) | |
0 | |
=> (fnil + 0) | |
0 |