Skip to content

Instantly share code, notes, and snippets.

@defiant
Created August 27, 2013 22:40
Show Gist options
  • Save defiant/6360045 to your computer and use it in GitHub Desktop.
Save defiant/6360045 to your computer and use it in GitHub Desktop.
World Bridge Federation new IMP to VP scale implementation in Javascript
(function(){
var tau,
denom;
tau = (Math.sqrt(5)-1)/2;
denom = 1 - Math.pow(tau, 3);
var V = [], i=0;
var B = 15 * Math.sqrt(8); // test for 8 Boards
for (var i = 0; i <= Math.ceil(B); i++) {
V[i] = Math.min(2000, Math.round(convert(i, B)));
};
correct(V);
function convert(margin, B){
return (1000 + 1000 * (1.0 - Math.pow(tau, 3.0 * margin/B)) / denom);
}
function correct(V){
var ok = false;
while(!ok){
ok = false;
for (i = 1; i < V.length - 1; i++) {
if ((V[i+1] - V[i]) > (V[i] - V[i-1])) {
V[i]++;
ok = true;
}
}
}
return V;
}
// print results
for (var i = 0; i < V.length; i++) {
var v = V[i]/100;
console.log(i + ": " +v);
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment