Skip to content

Instantly share code, notes, and snippets.

@mstefarov
Forked from MrBluePotato/gist:8468431
Last active January 3, 2016 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mstefarov/8468451 to your computer and use it in GitHub Desktop.
Save mstefarov/8468451 to your computer and use it in GitHub Desktop.
// step 1: find index of largest value
// If there is a tie, the last of the tied worlds will be chosen
World chosenWorld;
int maxVotes = int.MinValue, i = 0;
foreach (int votes in voteList) {
if ((chosenWorld == null) || (votes > maxVotes)) {
maxVotes = votes;
chosenWorld = worldList[i];
}
i++;
}
// step 2: print the results, if you want
Server.Message("World {0} won with {1} votes!", chosenWorld.Name, maxVotes);
// step 3: there is no step 3, you're done
return chosenWorld;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment