Created
October 24, 2013 08:34
-
-
Save ianonavy/7133361 to your computer and use it in GitHub Desktop.
Really inefficiently hacks http://www.loper-os.org/bad-at-entropy/manmach.html.
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
/* | |
Generates a perfect solution to http://www.loper-os.org/bad-at-entropy/manmach.html. | |
Naive algorithm: Maintain array of correct solution so far. Repeat '1' adding each to the solution until the machine scores. When it scores, save the solution, reset, and re-enter the solution up until right before it fails. Toggle between '1' and '0' and continue repeating until the machine scores. Do this until the solution array is size n. | |
First 1000 digits: | |
1111100001111000010011101111000001010011010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111010001110100011101000111 | |
*/ | |
var n = 60; // number of digits to generate | |
var solution = new Array(); | |
var machScore = document.getElementById('machscore'); | |
var bit = 1; | |
var count; | |
Reset(); | |
for (count = 0; count < n; count++) { | |
Move(bit); | |
if (machScore.textContent !== '0') { | |
Reset(); | |
var arrayLength = solution.length; | |
for (var arrayCount = 0; arrayCount < arrayLength; arrayCount++) { | |
Move(solution[arrayCount]); | |
} | |
bit = bit ? 0 : 1; // toggle bit | |
count--; | |
} else { | |
solution.push(bit); | |
} | |
} | |
var solutionString = ""; | |
var arrayLength = solution.length; | |
for (var arrayCount = 0; arrayCount < arrayLength; arrayCount++) { | |
solutionString += solution[arrayCount]; | |
} | |
console.log(solutionString); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment