Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,12 @@
|
|||
;; the initial level
|
||||
(def level (atom 41))
|
||||
|
||||
;; the probability of success
|
||||
(def prob 0.5001)
|
||||
|
||||
|
||||
(defn step
|
||||
[]
|
||||
(let [success (< (rand) prob)]
|
||||
(swap! level (if success inc dec))
|
||||
success) )
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
(defn step-up1
|
||||
"Straightforward implementation: keep track of how many level we
|
||||
need to ascend, and stop when this count is zero."
|
||||
[]
|
||||
(loop [deficit 1]
|
||||
(or (zero? deficit)
|
||||
(recur (if (step) (dec deficit)
|
||||
(inc deficit)))) ) )
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
(defn step-up2
|
||||
"Non-tail-recursive. No numbers."
|
||||
[]
|
||||
(if (not (step))
|
||||
(do (step-up2) ;; undo the fall
|
||||
(step-up2) ;; try again
|
||||
)
|
||||
true))
|
||||
Loading…
Add table
Add a link
Reference in a new issue