Skip to content

Instantly share code, notes, and snippets.

@foogoof
Created February 21, 2010 00:58
Show Gist options
  • Save foogoof/310030 to your computer and use it in GitHub Desktop.
Save foogoof/310030 to your computer and use it in GitHub Desktop.
(defstruct chopstick :id :holder)
(defstruct philosopher :name :left-stick :right-stick)
(defn make-chopstick [id]
(struct chopstick id (ref "")))
(defn set-table [philosophers]
(let [stick-count (max 2 (count philosophers))
stick-seq (map make-chopstick (range stick-count))
stick-cycle (cycle (take stick-count stick-seq))]
(map (fn [name [left right]] (struct philosopher name left right))
philosophers
(partition 2 1 stick-cycle))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment