Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -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) )

View file

@ -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)))) ) )

View file

@ -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))