Skip to content

Instantly share code, notes, and snippets.

(defn unfold
"Next and done? are functions that operate on a seed. next should
return a pair, [value new-seed]; the value half of the pair is
inserted into the resulting list, while the new-seed is used to
continue unfolding. Notably, the value is never passed as an
argument to either next or done?."
[next done? seed]
((fn unfold*
[seed]
(lazy-seq
(defn take-randnth [num coll]
(take num
(rest
(map first
(iterate (fn [[ret items]]
(let [idx (rand-int (count items))]
[(items idx)
(subvec (assoc items idx (items 0))
1)]))
[nil
anonymous
anonymous / gist:621663
Created October 12, 2010 04:35
(ns mandel
(:require [clojure.contrib.math :as math])
(:gen-class))
(defn complex [r i]
[(double r) (double i)])
(defn add [[r1 i1] [r2 i2]]
[(+ r1 r2) (+ i1 i2)])