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 fib [n] | |
(def memo (ref {})) ;create a ref to memo | |
(for [k (range (inc n))] | |
(do | |
(if (> k 1) | |
(dosync (alter memo conj [k (+ (@memo (- k 1)) (@memo (- k 2)))]) ;update memo with new pair | |
) |
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 fib [n] | |
(def memo {0 0 1 1}) | |
(for [k (range (inc n))] | |
(when (> k 1) | |
(assoc memo k (+ (memo (- k 1)) (memo (- k 2))))) | |
) | |
(memo 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
(let [origin (java.awt.Point. 0 0)] | |
(set! (.x origin) 15) ;; Assert failed: set! target must be a field or symbl naming a var targetexpr... | |
(str origin)) | |
(let [origin (java.awt.Point. 0 0)] | |
(set! (.-x origin) 15) ;; this works dnolen example in another problem resolution | |
(str origin)) |
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 multiple-trials [m n] | |
( loop [m m n n acc []] | |
(if (> m 0) | |
(conj acc (compute-winnings-for-a-trial n)) | |
acc) | |
(recur (dec m) n acc))) |
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 [fns (loop [i 0 ret []] | |
(if (< i 10) | |
(recur (inc i) (conj ret (fn [] i))) | |
ret))] | |
(map #(%) fns)) |
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 weave | |
([a-seq] | |
(weave (first a-seq) (rest a-seq))) | |
([x a-seq] | |
(defn weave-helper [x a-seq acc n] | |
(println "In weave: Sequence is: " a-seq) | |
(cond (nil? a-seq) (cons x '()) |