Paste number 45079: Bookie Math

Paste number 45079: Bookie Math
Pasted by: Chiao
When:1 year, 11 months ago
Share:Tweet this! | http://paste.lisp.org/+YS7
Channel:None
Paste contents:
Raw Source | XML | Display As
(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)))))

(defun table (n)
  (let ((thresh (floor (/ n 2))))
    (format t "~8a~6a~%" "Score" "Bet")
    (dotimes (i (+ thresh 1))
      (dotimes (j (+ i 1))
        (format t "~4a~4a~6a~%" i j (bet 100.0 n i j))))))

;;(table 5)                                                                                                                   
;; Score   Bet                                                                                                                
;; 0   0   37.5                                                                                                               
;; 1   0   37.5                                                                                                               
;; 1   1   50.0                                                                                                               
;; 2   0   25.0                                                                                                               
;; 2   1   50.0                                                                                                               
;; 2   2   100.0

This paste has no annotations.

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.