Created
December 1, 2014 01:10
-
-
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.
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
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