Skip to content

Instantly share code, notes, and snippets.

View kitofr's full-sized avatar

Kristoffer Roupé kitofr

  • Stockholm, Sweden
View GitHub Profile
@kitofr
kitofr / gist:1220144
Created September 15, 2011 18:59
game of life?
(def width 50)
(def height 50)
(defn populated? [pos]
true)
(defn unpopulated? [pos]
false)
(defn neighbors [pos]
@kitofr
kitofr / extract.clj
Created July 27, 2011 15:27
Extract data from a pivotal tracker project with Clojure CLR
(import '(System.Reflection Assembly))
(Assembly/LoadWithPartialName "System.Xml")
(import '(System.Xml XmlDocument))
(import '(System DateTime))
(def yaml "\ntype: %s\nname: %s\ncreated at: %s\naccepted at: %s\n")
(def csv "%s;%s;%s;%s\n")
(def types '("release" "feature" "bug"))
(def xml (doto (XmlDocument.) (. Load "11621.xml")))
#(loop [f %1 s %2 c ()]
(if (or
(empty? f)
(empty? s))
(reverse c)
(recur (rest f) (rest s) (conj c (first f) (first s)))))
#(loop [coll %1 n %2 c ()]
(if (empty? coll)
(reverse c)
(recur (rest coll) n (into c (repeat n (first coll))))))
;http://4clojure.com/problem/42
#(loop [n % f 1]
(if (= n 1)
f
(recur (dec n) (* f n))))
#(loop [col % c ()]
(cond (empty? col) (reverse c)
(= (first col) (first c)) (recur (rest col) c)
:else (recur (rest col) (cons (first col) c))))
;http://4clojure.com/problem/34
#(loop [from %1 to %2 c ()]
(if (= from to)
(reverse c)
(recur (inc from) to (conj c from))))
;http://4clojure.com/problem/32
#(loop [col % c ()]
(if (empty? col)
(reverse c)
(recur (rest col)
(cons (first col) (cons (first col) c)))))
;http://4clojure.com/problem/26
#(loop [n % seq []]
(letfn [(fib [x]
(if (<= x 2)
1
(+ (fib (- x 2)) (fib(- x 1)))))]
(if (= n 0)
seq
(recur (dec n) (cons (fib n) seq)))))
;http://4clojure.com/problem/23
#(loop [coll % stk []]
(if (empty? coll)
stk
(recur (next coll) (cons (first coll) stk))))