Skip to content

Instantly share code, notes, and snippets.

@dave-f
Created September 4, 2012 12:10
Show Gist options
  • Save dave-f/3620652 to your computer and use it in GitHub Desktop.
Save dave-f/3620652 to your computer and use it in GitHub Desktop.
Quick bit of Emacs Lisp to automatically pick bowlers and assign them to lanes
; Define bowler names and lane size, then run `create-bowling-teams-buffer' to display
(defconst bowlers
'("Player 1"
"Player 2"))
(defconst lane-size 6)
(defun create-bowling-teams-buffer ()
(interactive)
(pop-to-buffer (get-buffer-create "*Bowling Teams*"))
(erase-buffer)
(let ((random-list (create-random-list))
(loop-count 0)
(current-lane 0)
(extra-bowlers 0)
(current-bowler 0)
(minimum-on-team 0)
(num-lanes (/ (length bowlers) lane-size)))
(if (> (% (length bowlers) lane-size) 0)
(setq num-lanes (1+ num-lanes)))
(setq minimum-on-team (/ (length bowlers) num-lanes))
(insert-string "Total bowlers " (length bowlers) "\n")
(insert-string "Lanes needed " num-lanes "\n\n")
(setq extra-bowlers (- (length bowlers) (* num-lanes minimum-on-team)))
(while (< current-lane num-lanes)
(insert-string "Team " (1+ current-lane) "\n")
(insert-string "------\n")
(setq loop-count 0)
(while (< loop-count minimum-on-team)
(insert-string (elt bowlers (elt random-list current-bowler)) "\n")
(setq current-bowler (1+ current-bowler))
(setq loop-count (1+ loop-count)))
(if (> extra-bowlers 0)
(progn
(insert-string (elt bowlers (elt random-list current-bowler)) "\n")
(setq current-bowler (1+ current-bowler))
(setq extra-bowlers (1- extra-bowlers))))
(insert-string "\n")
(setq current-lane (1+ current-lane)))))
(defun create-random-list ()
(let (num-list this-num)
(setq num-list (make-list 0 0))
(while (not (= (length num-list) (length bowlers)))
(setq this-num (abs (% (random) (length bowlers))))
(if (not (member this-num num-list))
(add-to-list 'num-list this-num)))
num-list))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment