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 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 |
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 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 |
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 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)]) |
NewerOlder