#tournament #algorithm #team #round #match #vector #respective

round_robin

Create a vector of rounds and their respective matches in a tournament, using the Round-robin algorithm

7 releases (2 stable)

1.0.1 Jul 6, 2024
1.0.0 Jul 18, 2021
0.1.31 May 23, 2021

#385 in Algorithms

Download history 8/week @ 2024-09-10 3/week @ 2024-09-17 5/week @ 2024-09-24 7/week @ 2024-10-01

279 downloads per month

MIT license

5KB
53 lines

Round-robin algorithm

Create a vector of rounds using the Round-robin algorithm.

Example using strings:

let teams = vec!["A", "B", "C", "D"];
let rounds = generate_rounds(teams);
// [("A", "D"), ("C", "B"), ("A", "C"), ("B", "D"), ("A", "C"), ("B", "D")]

Example using numbers:

let teams = vec![1, 2, 3, 4];
let rounds = generate_rounds(teams);
// [(1, 4), (3, 2), (1, 3), (2, 4), (1, "C"), (2, 4)]

Example using structs:

#[derive(Debug, Clone)]
struct Team { name: &'static str }
let teams = vec![
    Team { name: "Liverpool" }, Team { name: "Chelsea" },
    Team { name: "M. City" }, Team { name: "M. United" },
];
let rounds = generate_rounds(teams);
// [(Team { name: "Liverpool" }, Team { name: "M. United" }), (Team { name: "M. City" }, Team { name: "Chelsea" }), (Team { name: "Liverpool" }, Team { name: "M. City" }), (Team { name: "Chelsea" }, Team { name: "M. United" }), (Team { name: "Liverpool" }, Team { name: "M. City" }), (Team { name: "Chelsea" }, Team { name: "M. United" })]

No runtime deps