Skip to content

Instantly share code, notes, and snippets.

@mkuklis
Forked from 140bytes/LICENSE.txt
Last active February 5, 2023 03:20
Show Gist options
  • Save mkuklis/5942586 to your computer and use it in GitHub Desktop.
Save mkuklis/5942586 to your computer and use it in GitHub Desktop.
function(
a, // old rating
b, // opponent rating
c, // result 0 - lost 0.5 - draw 1 - win
e, // expected probability
k // k-factor
){
e = 1 / (1 + Math.pow(10, ((b - a) / 400))); // calculate probability
// find k-factor
if (b < 2100) k = 32;
else if (b >= 2100 && b <= 2400) k = 24;
else if (b > 2400) k = 16;
return b + k * (c - e); // return new rating
}
function(a,b,c,e,k){e=1/(1+Math.pow(10,((b-a)/400)));if(b<2100)k=32;else if(b>=2100&&b<=2400)k=24;else if(b>2400)k=16;return b+k*(c-e)}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"name": "elo",
"description": "Elo rating calculation",
"keywords": [
"game",
"elo",
"rating",
"calculation"
]
}
<!DOCTYPE html>
<title>Foo</title>
<div>Expected value: <b>1316</b></div>
<div>Actual value: <b id="ret"></b></div>
<script>
var elo = function(a,b,c,e,k){e=1/(1+Math.pow(10,((b-a)/400)));if(b<2100)k=32;else if(b>=2100&&b<=2400)k=24;else if(b>2400)k=16;return b+k*(c-e)}
document.getElementById( "ret" ).innerHTML = elo(1300, 1300, 1);
</script>
@atk
Copy link

atk commented Jul 8, 2013

Allow me to be your caddy for this code golf:

function(a,b,c){return b+(b<2100?32:b<2401?24:16)*(c-(1/(1+Math.pow(10,((b-a)/400)))))}

@mkuklis
Copy link
Author

mkuklis commented Jul 19, 2013

@atk fantastic! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment