Last active
February 29, 2020 03:16
-
-
Save Reprevise/7b59017070065c07df804ff862a51d54 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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