Skip to content

Instantly share code, notes, and snippets.

@Reprevise
Last active February 29, 2020 03:16
Show Gist options
  • Save Reprevise/7b59017070065c07df804ff862a51d54 to your computer and use it in GitHub Desktop.
Save Reprevise/7b59017070065c07df804ff862a51d54 to your computer and use it in GitHub Desktop.
void main() {
start(['Jim', 'John', 'Nicole', 'Smith', 'What', 'Best team', 'Dart', 'Flutter', 'C#', 'bungo', 'Odd team']);
}
List<String> teams;
List<List<String>> bracket = [];
int maxRounds;
void start(List<String> origTeams) {
if (origTeams.length < 4) {
return;
}
teams = List<String>.from(origTeams);
if (teams.length.isOdd) {
teams.add('bye_week');
}
maxRounds = (teams.length - 1);
var splitTeams = splitList(teams);
var rotatedTeams = splitTeams;
for (var i = 1; i <= 3; i++) {
print('Round: $i');
for (var b = 0; b < rotatedTeams[0].length; b++) {
bracket.add([rotatedTeams[0][b], rotatedTeams[1][b]]);
print([rotatedTeams[0][b], rotatedTeams[1][b]]);
}
rotatedTeams = rotateTeams(splitTeams);
}
}
List<List<String>> splitList(List<String> split) {
var first = split.sublist(0, split.length ~/ 2);
var last = split.sublist(split.length ~/ 2);
return []..add(first)..add(last.reversed.toList());
}
List<List<String>> rotateTeams(List<List<String>> rotate) {
var firstList = rotate[0];
var secondList = rotate[1];
var itemToMove = firstList.removeLast();
secondList.insert(secondList.length - 1, itemToMove);
var moveToFirst = secondList.removeAt(0);
firstList.insert(1, moveToFirst);
return []..add(firstList)..add(secondList);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment