// --------------------
// This simulation tests the guessing game, by forcing values for K
// Based on the number of bars it will step from zero to 1, and graph the value on the chart
// If you opt to set progressionSimulation to false, it will only run the common guessing game without forcing a value
// Basically if a bar has the values; 74.8 / 0.5, it means that if you use 0.5 as K, your chances of guessing the number are ~75%
// --------------------
// VARS,
// You are allowed to mess up this values:
var bars = 10;
var progressionSimulation = true;
// --------------------
// INIT
$( document ).ready(function() {
$('.bars').css("width", (bars+1) * 42 + "px");
for(var i=0; i<=bars ; i++) {
var result = guessingGame( 100000, progressionSimulation ? i / bars : null );
var barVal = Math.floor((i / bars) * 100) / 100;
$(".bars").append("<div>"+Math.floor(result*1000)/10+"<br/><br/>"+barVal+"</div>")
.children().eq(i)
.css("height", (result * 300) + "px")
.css("margin-top", 295-(result * 300) + "px");
}
});
// --------------------
// GUESSING GAME FUNCTION
function guessingGame(testcases, point) {
var correct = i = 0,
r = Math.random;
for (i=testcases;i;i--) {
var a = r(), b = r(), k = point != null ? point : r();
correct += (k < a && a > b) || (k > a && a < b);
}
return correct / testcases;
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.