comparison clojure/com/aurellem/run/util.clj @ 328:35960b03693f

improved delayed-difference with memoization
author Robert McIntyre <rlm@mit.edu>
date Thu, 05 Apr 2012 15:05:08 -0500
parents fe6fd2323264
children a452deec2882
comparison
equal deleted inserted replaced
327:fe6fd2323264 328:35960b03693f
60 test-val (metric test)] 60 test-val (metric test)]
61 (if (= test-val baseline) 61 (if (= test-val baseline)
62 (recur test high) 62 (recur test high)
63 (recur low test)))))))) 63 (recur low test))))))))
64 64
65
65 (defn delayed-difference 66 (defn delayed-difference
66 [base alt delay difference-metric [moves root :as script]] 67 [base alt delay difference-metric [moves root :as script]]
67 (let [generator 68 (let [generator
68 (memoize 69 (memoize
69 (fn [n] 70 (fn gen [n]
70 (run-moves 71 (run-moves
71 root 72 root
72 (repeat n base)))) 73 (repeat n base))))
73 len 74 len
74 (binary-search 75 (binary-search
75 (fn [n] 76 (memoize (fn [n]
76 (= (difference-metric 77 (= (difference-metric
77 (run-moves 78 (run-moves
78 (generator n) 79 (generator n)
79 (concat [alt] (repeat delay base)))) 80 (concat [alt] (repeat delay base))))
80 (difference-metric 81 (difference-metric
81 (run-moves 82 (run-moves
82 (generator n) 83 (generator n)
83 (repeat (inc delay) base)))))) 84 (repeat (inc delay) base)))))))
84 new-moves (concat moves (repeat len base) [alt]) 85 new-moves (concat moves (repeat len base) [alt])
85 new-state (run-moves (generator len) [alt])] 86 new-state (run-moves (generator len) [alt])]
86 [new-moves new-state])) 87 [new-moves new-state]))
87 88
88 (def x-position-address 0xD361) 89 (def x-position-address 0xD361)