Skip to content

Instantly share code, notes, and snippets.

@ianonavy
Created October 24, 2013 08:34
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 ianonavy/7133361 to your computer and use it in GitHub Desktop.
Save ianonavy/7133361 to your computer and use it in GitHub Desktop.
/*
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