Skip to content

Instantly share code, notes, and snippets.

@Goodwine
Created December 1, 2014 01:10
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 Goodwine/e719e1954aec742ea190 to your computer and use it in GitHub Desktop.
Save Goodwine/e719e1954aec742ea190 to your computer and use it in GitHub Desktop.
Gist Shows the current implementation of how TopCoder assigns placement in a room.
x = [];
n = 35000;
for (i = 0; i < n; i++) {
x.push({
userName: Math.random(),
totalPoints: Math.random() * 100000,
})
}
time = new Date().getTime();
// Implementation "bubbles" down the placement, which takes big-theta(n^2) *I think ;-;*
updateCoderPlacement = function (coders) {
coders.forEach(function (item) {
item.roomPlace = 1;
coders.forEach(function (other) {
if (item.userName !== other.userName && item.totalPoints < other.totalPoints) {
item.roomPlace += 1;
}
});
});
};
updateCoderPlacement(x);
console.log('Total Time in updateCoderPlacement:', (new Date().getTime() - time) / 1000, 'seconds.');
// Total Time in updateCoderPlacement: 50.688 seconds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment