Created
February 21, 2010 00:58
-
-
Save foogoof/310030 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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