Arc Forumnew | comments | leaders | submitlogin
5 points by pg 5628 days ago | link | parent

This reproduces the behavior of yours (possibly too) exactly, including giving the user 9 guesses and saying "1 tries" if you get it right the first time. The return value is different though.

    (def guess ((o tries 1) (o r (rand 100)))
      (when (< tries 10)
        (pr "your guess: ")
        (let y (read)
          (prn)
          (if (is y r)
              (do (prn "yay")                  
                  (pr "you got it in " tries " tries."))
              (do (prn y " is too " (if (< y r) "low" "high"))
                  (guess (+ tries 1) r))))))


1 point by coconutrandom 5628 days ago | link

Ahh... concise and readable. Thank you!

[edit] I just found that the "o" makes the arguments optional. That explained a lot.

-----