[quiz] [QUIZ 5b & 5e] Date differences, and betting (Larry Clapp) [spoiler]

Chiao-Lun Cheng chiao at cal.berkeley.edu
Wed Jul 25 01:34:15 UTC 2007


My solution to the betting problem:

(defun bet (total maxgames score1 score2 &optional err-check-off)
  (let ((thresh (floor (/ maxgames 2))))
    (unless err-check-off
      (cond ((evenp maxgames)
             (error "Only odd numbers of total games allowed"))
            ((or (> score1 thresh)
                 (> score2 thresh))
             (error "Scores must be below half the total number of games"))
            ((or (< maxgames 0)
                 (< score1 0)
                 (< score2 0))
             (error "maxgame, score1 and score2 must not be negative"))))
    (cond ((or (= score1 (1+ thresh))
               (= score2 (1+ thresh)))
           0)
          ((and (= score1 thresh)
                (= score2 thresh))
           total)
          (t (/ (+ (bet total maxgames (1+ score1) score2 t)
                   (bet total maxgames score1 (1+ score2) t))
                2)))))

Given the you bet $a this round, and $b / $c next round, then a
win-loss or a loss-win must put you back at the same value, meaning
that

a - b = -a +c

and therefore a = (b+c)/2

That's the recursion that took me some time to realize. Otherwise the
coding is straightforward.

--
*******************************************
 Chiao-Lun Cheng
 Van Voorhis Group
 Department of Chemistry, Room 6-234
 Massachusetts Institute of Technology
 77 Massachusetts Avenue
 Cambridge, MA 02139-4307

 Email  : chiao at mit.edu
 Tel    : +1 (617) 253-1539
 Website    : http://zeno.unixboxen.net
*******************************************



More information about the Quiz mailing list