(function(h, answerLength, limit){
var
letterSet = "acdegilmnoprstuw",
reduction = 7,
answered = false,
pos = 0,
ltrIdx = 0,
answer = "",
hash = h,
ct = 0;
var reduce = function(){
var oldhash;
// console.log(answer,":",hash, ltrIdx, pos);
// answer is the current guess being built up.
// answer is also effectively an array representing our past guesses / progress
// we make a guess 1 letter position at a time.
// when a rule is violated we can "backup a step" and modify our guess--
// incrementing based on the "progress" so far
// seed is one letter
// hash is our hash that is being reduced. Our goal is reached when we have both an answer
// that is the right length and a hash that has been reduced to the hash seed ("reduction")
seed = letterSet[ltrIdx];
//cache hash for regression
oldhash = hash
//reduce hash
hash = (hash - letterSet.indexOf(seed))/37;
// console.log("seed:",seed, "answer:", answer, "hash:", hash, oldhash, letterSet.indexOf(seed));
var backup = false;
if ((hash % 1) === 0) {
// hash divides evenly ==> so far so good
if( hash > reduction && answer.length < (answerLength - 1) ){
// potentially the right track; update our answer and keep going
answer = seed + answer;
ltrIdx = 0;
return false;
} else if (hash == reduction && answer.length == ( answerLength-1)){
// found the answer?
answer = seed + answer;
return true;
} else if (hash == reduction){
// right hash but wrong answer (answer is too long) so back up a position
} else if (answer.length == answerLength){
// wrong hash but right length so backup up a position
}
} else {
// hash is not an integer
if( ltrIdx < letterSet.length ){
//have more letters to try for this same position
// (increment the seed)
ltrIdx++;
...
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.