Skip to content

Instantly share code, notes, and snippets.

(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)))
*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)
@amalloy
amalloy / extract.clj
Last active December 18, 2015 18:49 — forked from mattdeboard/extract.clj
;; 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]
(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)))))))
;;;; my/project/dummy.clj
(ns my.project.dummy
(:gen-class))
(defn -main [& args]
(require 'my.project.main)
(apply (resolve 'my.project.main/-main) args))
(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)))
(let [inputs [{:date1
[{:user "user 1"
:metric1 1
:metric2 2}
{:user "user 2"
:metric1 3
:metric2 4}]}
{:date2
[{:user "user 1"
:metric1 5
@amalloy
amalloy / install-graphite-ubuntu-10.04.sh
Last active December 10, 2015 19:08 — forked from MikeGrace/install-graphite-ubuntu-10.04.sh
Added some more steps I needed
####################################
# 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
(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])
(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))