Initial commit
This commit is contained in:
18
JavaScript/code_cycle.js
Normal file
18
JavaScript/code_cycle.js
Normal file
@@ -0,0 +1,18 @@
|
||||
const total_attempts = 256*256*256;
|
||||
var successful_attempts = 0;
|
||||
|
||||
for (var a = 0; a < 256; a++)
|
||||
{
|
||||
for (var b = 0; b < 256; b++)
|
||||
{
|
||||
for (var c = 0; c < 256; c++)
|
||||
{
|
||||
if (a + b + c > 300)
|
||||
successful_attempts++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log("Iterations: " + total_attempts);
|
||||
console.log("Successful checks: " + successful_attempts);
|
||||
console.log("Probability: " + (successful_attempts/total_attempts));
|
||||
28
JavaScript/code_unoptimised.js
Normal file
28
JavaScript/code_unoptimised.js
Normal file
@@ -0,0 +1,28 @@
|
||||
const total_attempts = 15000000;
|
||||
var successful_attempts = 0;
|
||||
|
||||
var get_random = () => {
|
||||
return Math.floor(Math.random() * 256);
|
||||
}
|
||||
|
||||
for (var i = 0; i < total_attempts; i++)
|
||||
{
|
||||
/*
|
||||
var a = Math.floor(Math.random() * 256);
|
||||
var b = Math.floor(Math.random() * 256);
|
||||
var c = Math.floor(Math.random() * 256);
|
||||
*/
|
||||
|
||||
var a = get_random();
|
||||
var b = get_random();
|
||||
var c = get_random();
|
||||
|
||||
if (a + b + c > 300)
|
||||
{
|
||||
successful_attempts++;
|
||||
}
|
||||
}
|
||||
|
||||
console.log("Iterations: " + total_attempts);
|
||||
console.log("Successful checks: " + successful_attempts);
|
||||
console.log("Probability: " + (successful_attempts/total_attempts));
|
||||
Reference in New Issue
Block a user