Given 3 Teams (A, B, C), we want to organize a tournament schedule such that every team plays every other team exactly once. Here is a valid schedule for these 3 teams:
- A - B
- B - C
- A - C
How about if we have N teams? Devise a general purpose algorithm that generates tournament schedules for N teams.
(defn schedule-teams [teams]
(map
vec
(distinct
(remove nil?
(for [x teams
y teams]
(when (not (= x y))
(apply sorted-set [x y])))))))
(schedule-teams [:a :b :c])
([:a :b] [:a :c] [:b :c])
(schedule-teams [:a :b :c :d :e :f :g])
([:a :b] [:a :c] [:a :d] [:a :e] [:a :f] [:a :g] [:b :c] [:b :d] [:b :e] [:b :f] [:b :g] [:c :d] [:c :e] [:c :f] [:c :g] [:d :e] [:d :f] [:d :g] [:e :f] [:e :g] [:f :g]