More functional way to do this?
问题 This post of mine discusses Thomson's paradox, and simulates it in Clojure. The state function returns the state of the lamp at time = t. (defn thomsons-lamp [] (iterate (fn [[onoff dur]] [(not onoff) (/ dur 2)]) [true 1])) (defn state [t] (let [t-vals (map second (thomsons-lamp))] (loop [i 1] (if (<= t (apply + (take i t-vals))) ((comp first last) (take i (thomsons-lamp))) (recur (inc i)))))) How do I define a cleaner state function (preferably without loop/recur)? 回答1: The only sins here