JSFiddle - React, Tailwind, and code Playground

by Gerald Gillespie

JavaScript

var h = 930846109532517; 

 var letterSet = "acdegilmnoprstuw"

var rgx = New RegExp("^[" + letterSet + "]*$","g");

var reduction = 7;

var patience = 100000;
var ct =0;

/* 

Int64 hash (String s) {
   Int64 h = 7
   String letters = "acdegilmnoprstuw"
   for(Int32 i = 0; i < s.length; i++) {
       h = (h * 37 + letters.indexOf(s[i]))
       
       // oldh = 
   }
   return h
}

*/

var reduce = function( seed, answer, hash ){
	// seed is one letter
  // answer the built-up string so far
	
  
  if ( ((ct++) % patience == 0 ) &&  confirm(" at " + ct + ".  Keep going?") ){
    hash = (hash - letterSet.indexOf(seed))/37;
    answer = seed + answer;

    if (hash <= reduction && answer.length = 9){
      //success!
      // reverse it to be the result
      console.log( "answer:", answer,"hash:", hash, "success!")
      return answer;

    } else if(answer.length > 9){
      console.log( "answer:", answer,"hash:", hash, "failed. answer is too long")
      // enter recursion
      return answer;
    } else if(hash == reduction){
        console.log( "answer:", answer,"hash:", hash, 
        	"failed. answer is not long enough and we have reached hash reduction"
        );
        return answer;

    } else if (hash < reduction){
      console.log( "answer:", answer,"hash:", hash, "failed. answer is not long enough and we have surpassed hash reduction");
        return answer;
    } else {
      //keep going 
      seed = getSeed();
      
      return reduce( seed, answer, hash);
    }
  } else {
  	console.log("execution not continued by prompt");
   	return;
  }

} // reduce() ;

var getSeed = function(){
	return letterSet[Math.floor( Math.random() * 9 )];
}

console.log("hi");
reduce( getSeed(), "", h);