Diferencia entre revisiones de «Sistema de todos contra todos»

Contenido eliminado Contenido añadido
Deshecha la edición 32260403 de 190.67.58.55 (disc.)
Línea 106:
 
Si hay un número impar, se puede asignar un número especial (para totalizar los pares) para designar al equipo que quedará libre. Para dobles rondas, simplemente se repite el sistema anterior, pero se alternan las localías.
 
== Algoritmo de selección en Ruby ==
 
A continuación mostramos un algoritmo Round-Robin a doble partido para un torneo de liga como la LFP:
 
<pre>
def make_rounds(clubs)
#If odd insert dummy club
if clubs.length % 2 == 1
clubs << "X"
end
rounds_home = []
rounds_away = []
num_rounds = clubs.length - 2
num_matches = clubs.length / 2 - 1
 
for i in (0..num_rounds)
matches_home = []
matches_away = []
for j in (0..num_matches)
matches_home << [clubs[j], clubs[num_rounds - j + 1]] #Home match
matches_away << [clubs[num_rounds - j + 1], clubs[j]] #Away match
end
rounds_home << matches_home
rounds_away << matches_away
#rotating the teams
last = clubs.pop
clubs.insert(1, last)
end
rounds_away.each { |x| rounds_home << x}
return rounds_home
end
 
def print_rounds(rounds)
i = 1
rounds.each do |round|
puts "Round: #{i}"
round.each do |match|
puts "Match: #{match[0]} - #{match[1]}"
end
i += 1
end
end
 
 
clubs = ("A".."T").collect {|x| x}
rounds = make_rounds(clubs)
print_rounds(rounds)
</pre>
 
== Tenis ==