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 dijkstra | |
([a] | |
(dijkstra a (find-walls a) (find-lowest a))) | |
([a closed open-cells] | |
(loop [open open-cells] | |
(when (seq open) | |
(recur (reduce (fn [newly-open [i v]] | |
(reduce (fn [acc dir] | |
(if (or (closed dir) (open dir) | |
(>= (inc v) (hiphip/aget a n))) |
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
*Control.Memoize> let f = ([1,2..10^6] !!) | |
*Control.Memoize> time $ f 999999 | |
(1000000,60004000000) | |
*Control.Memoize> time $ f 999999 | |
(1000000,8001000000) | |
*Control.Memoize> let g = memoize f | |
*Control.Memoize> time $ g 999999 | |
(1000000,4000000000) | |
*Control.Memoize> time $ g 999999 | |
(1000000,0) |
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 buffer is for notes you don't want to save, and for Lisp evaluation. | |
;; If you want to create a file, visit that file with C-x C-f, | |
;; then enter the text in that file's own buffer. | |
(defn extract-render-listener | |
"A RenderListener implementation that extracts images from a PDF and | |
writes them to disk." | |
[path] | |
(reify RenderListener | |
(renderImage [_ render-info] |
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
(fn remove-once [pred coll] | |
(lazy-seq | |
(when-let [coll (seq coll)] | |
(let [x (first coll), xs (rest coll)] | |
(if (pred x) | |
xs | |
(cons x (remove-once pred xs))))))) |
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
;;;; my/project/dummy.clj | |
(ns my.project.dummy | |
(:gen-class)) | |
(defn -main [& args] | |
(require 'my.project.main) | |
(apply (resolve 'my.project.main/-main) args)) | |
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
(defmulti group-data :group-by) | |
(clojure.tools.macro/macrolet [(impl [key expr] | |
`(defmethod group-data ~key [kvs#] | |
(->> (:data kvs#) | |
(group-by (fn [kv#] | |
(let [~'date (:time kv#)] | |
~expr))))))] | |
(impl :day (str (month date) "-" (day date) "-" (year date))) | |
(impl :month (str (month date) "-" (year date))) | |
(impl :year (year date))) |
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
(let [inputs [{:date1 | |
[{:user "user 1" | |
:metric1 1 | |
:metric2 2} | |
{:user "user 2" | |
:metric1 3 | |
:metric2 4}]} | |
{:date2 | |
[{:user "user 1" | |
:metric1 5 |
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
#################################### | |
# BASIC REQUIREMENTS | |
# http://graphite.wikidot.com/installation | |
# http://geek.michaelgrace.org/2011/09/how-to-install-graphite-on-ubuntu/ | |
# Last tested & updated 10/13/2011 | |
#################################### | |
sudo apt-get update | |
sudo apt-get upgrade |
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 algo2.unionfind) | |
(defprotocol DisjointSet | |
"A data structure that maintains informations on a number of disjoint sets." | |
(add-singleton [this x] "Add the element x to a new singleton set") | |
(connect [this x y] "Union the sets that x and y are in") | |
(get-canonical [this x] "Return the canonical element of the set x is in")) | |
(defrecord UFNode [value rank parent]) |
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 ack [m n] | |
(cond (zero? m) (inc n) | |
(zero? n) (ack (dec m) 1) | |
:else (ack (dec m) (ack m (dec n))))) | |
(defn ack-cps | |
([m n] (ack-cps m n identity)) | |
([m n k] | |
(loop [m m, n n, k k] | |
(cond (zero? m) (k (inc n)) |