Skip to content

Instantly share code, notes, and snippets.

@shinhirota
Created December 9, 2015 04:29
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 shinhirota/99a0fbd0616b15c3d4c2 to your computer and use it in GitHub Desktop.
Save shinhirota/99a0fbd0616b15c3d4c2 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/node
var minErr = 4;
for (var i = 1; i < 100000000; i++) {
var j = Math.floor(Math.PI * i);
var err = Math.abs(Math.PI - (j/i));
var err1 = Math.abs(Math.PI - ((j+1)/i));
if (err > err1) {
err = err1;
j = j+1;
}
if (minErr > err) {
minErr = err;
console.log("" + j + "/" + i + " = " + (j / i) + ", ERR=" + err);
if (err == 0) break;
}
}
console.log("DONE with i=" + i);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment