Created
August 12, 2016 02:58
-
-
Save kristovatlas/bdfe96829b54dd8c1bade0a94cc8dba0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- brute forces answer to http://alf.nu/ReturnTrue 'transitive' challenge --> | |
<html> | |
<head> | |
<script type="text/javascript"> | |
vals = [NaN, 0, 1, true, false, null, [0], undefined, new Boolean, "", "1", "0", Number(0), Number(1)]; | |
function sleep (time) { | |
return new Promise((resolve) => setTimeout(resolve, time)); | |
} | |
function get_rand (top) { | |
return Math.floor(Math.random() * top) + 1; | |
} | |
function transitive(x,y,z) { | |
return x && x == y && y == z && x != z; | |
} | |
function reset_vals () { | |
val1 = vals[get_rand(vals.length)] | |
val2 = vals[get_rand(vals.length)]; | |
while (val1 === val2) { | |
val2 = vals[get_rand(vals.length)]; | |
} | |
val3 = vals[get_rand(vals.length)]; | |
while (val1 === val3 || val2 === val3) { | |
val3 = vals[get_rand(vals.length)]; | |
} | |
} | |
var val1 = null; | |
var val2 = null; | |
var val3 = null; | |
console.log('started'); | |
sleep(10000).then(() => { | |
var num_tries = 0; | |
while (true) { | |
reset_vals(); | |
if (transitive(val1, val2, val3) === true) { | |
console.log("solution: " + val1 + '(' + typeof(val1) + '),' + val2 + '(' + typeof(val2) + '),' + val3 + '(' + typeof(val3) + ')'); | |
break; | |
} | |
num_tries++; | |
if (num_tries % 10000 == 0) { | |
console.log(num_tries + ' tries so far. Last: ' + val1 + ',' + val2 + ',' + val3); | |
} | |
} | |
console.log('stopped'); | |
}) | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment