Sha256: fb02fede9da46edf1facd40ec9856c07d19050526a211ccf36bc5341714aadb6

Contents?: true

Size: 386 Bytes

Versions: 1

Compression:

Stored size: 386 Bytes

Contents

require 'round_robin_tournament/version'

module RoundRobinTournament

  def self.schedule(array)
    array.push nil if array.size.odd?
    n = array.size
    pivot = array.shift
    games = (n - 1).times.map do
      array.rotate!
      [[array.first, pivot]] + (1...(n / 2)).map { |j| [array[j], array[n - 1 - j]] }
    end
    array.push pivot unless pivot.nil?
    games
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
round_robin_tournament-0.1.0 lib/round_robin_tournament.rb