<html>
<head>
<title>Number Sequence - RJM Programming - March, 2023 ... thanks to Dr Crypton's Mind Benders Introduction by Isaac Asimov</title>
<meta charset="UTF-8"/>
<style>
  td { text-align: center; background-color: #f0f0f0; }
</style>
<script type=text/javascript>
  var sharing=location.search.split('sharing=')[1] ? decodeURIComponent(location.search.split('sharing=')[1].split('&')[0]) : ""; 
  var pluss='';
  var startnum=3;
  var numinterval=1;
  var istart=false, fca=false;
  var score=0, goes=0, tsecs=0;
  var odateone=null, odatetwo=null;
  var suffixes=['Ace:01','Two:02','Three:03','Four:04','Five:05','Six:06','Seven:07','Eight:08','Nine:09','Ten:10','Jack:11','Queen:12','King:13'];
  var denominations=['Ace','Two','Three','Four','Five','Six','Seven','Eight','Nine','Ten','Jack','Queen','King'];
  var suits=['Spades','Clubs','Diamonds','Hearts'];
  var suittwos=[];
  var gd='';
  var cinlet=' ... Inlet';
  
  function checkit() {
    var suffix='';
    score--;
    goes++;
    if (gd == document.getElementById('mynum').value) {
      score+=3;
      fca=true;
     suffix=' ... Well done!';
      document.getElementById('score').innerHTML='Score: ' + score + '/' + goes + suffix + '';
      alert('Well done!  But just in case it was a fluke ...');
      //score=0;
      //goes=0;
      tsecs=0;
      fca=false;
      document.getElementById('score').innerHTML='Score: ' + score + '/' + goes + suffix + '';
      populate();
    } else {
      suffix=' ... No, it is not that number.';
      document.getElementById('score').innerHTML='Score: ' + score + '/' + goes + suffix + '';
    }
    document.getElementById('mynum').value='0';
  }
  
  function tadd() {
    if (!fca) { tsecs++; document.getElementById('isecs').innerHTML='' + tsecs;  }
  }
  
  function setup() {
    populate();
  }
  
  function numberih(inih, inlet) {
    var mm='', iz=0, aone=1;
    if (inih > 0) {
     //console.log('pre while 1 ... inih=' + inih + ' and ' + cinlet + '=' + inlet);
     cinlet='inlet';
     while (Math.pow(inlet, iz) < inih) {
      iz++;
     }
     iz--;
    }
    //alert('iz=' + iz + ' and inlet=' + inlet + ' and inih=' + inih);
    for (var iiz=iz; iiz>=0; iiz--) {
      aone=1;
      if (Math.pow(inlet, iiz) > inih) {
        mm+='0';
      } else if (Math.pow(inlet, iiz) == inih) {
        mm+='1';
        inih-=Math.pow(inlet, iiz)
      } else {
       aone++;
       //console.log('pre while 2');
       while (eval(aone * Math.pow(inlet, iiz)) <= inih) {
          aone++;
          if (eval('' + aone) >= 10) { return ''; }
        }
        aone--;
        mm+='' + aone;
        inih-=eval(aone * Math.pow(inlet, iiz));
      }
      //mm+='' + inih;
      //alert('iz=' + iz + ' and inlet=' + inlet + ' and inih=' + inih + ' and mm=' + mm);
    }
    return '' + mm;
  }
  
  function populate() {
    var one=-1, two=2;
    if (sharing.indexOf('.') != -1) {
      one=eval(sharing.split('.')[0]);
    } else {
      if (eval(Math.floor(Math.random() * 198767543) % 2) == 1) { one=1; } 
    }
    if (sharing.indexOf('.') != -1) {
      two=eval(sharing.split('.')[1]);
    } else {
      if (eval(Math.floor(Math.random() * 198767543) % 2) == 1) { two=1; } 
    }
    if (sharing.indexOf('.') != -1) {
      startnum=eval(sharing.split('.')[2]);
    } else if (eval(one * two) == -2) {
      startnum=9;
    } else if (eval(one * two) == 2) {
      startnum=3;
    } else if (eval(one * two) == -1) {
      startnum=eval(6 + Math.floor(Math.random() * 3));
    } else {
      startnum=Math.max(3,eval(-5 + Math.floor(Math.random() * 9)));
    }
    var istart=startnum;
    if (sharing.indexOf('.') != -1) {
      ih=eval(sharing.split('.')[3]);
    } else {
      ih=Math.max(33,Math.floor(Math.random() * 9987));
    }
    if (sharing == '' || pluss == '') {
    pluss='' + one + '.' + two + '.' + startnum + '.' + ih;
    }
    sharing='';
    //alert(1);
    document.getElementById('thefour').innerHTML='';
    cinlet=' ... Inlet';
    document.getElementById('thefour').innerHTML+='<td style="border:2px solid green;">' + numberih(ih, startnum) + '</td>';
    startnum+=eval(one * two);
    document.getElementById('thefour').innerHTML+='<td style="border:2px solid green;">' + numberih(ih, startnum) + '</td>';
    startnum+=eval(one * two);
    if (two == 1) {
    document.getElementById('thefour').innerHTML+='<td style="border:2px solid green;">' + numberih(ih, startnum) + '</td>';
    startnum+=eval(one * two);
    }
    document.getElementById('thefour').innerHTML+='<td style="border:2px solid green;">' + numberih(ih, startnum) + '</td>';
    startnum+=eval(one * two);
    //console.log('pre while 0');
    while (document.getElementById('thefour').innerHTML.indexOf('></td>') != -1) {
       startnum=istart;
       ih=Math.max(33,Math.floor(Math.random() * 9987));
       pluss='' + one + '.' + two + '.' + startnum + '.' + ih;
     cinlet=' ... Inlet';
    document.getElementById('thefour').innerHTML='';
    document.getElementById('thefour').innerHTML+='<td style="border:2px solid green;">' + numberih(ih, startnum) + '</td>';
    startnum+=eval(one * two);
    document.getElementById('thefour').innerHTML+='<td style="border:2px solid green;">' + numberih(ih, startnum) + '</td>';
    startnum+=eval(one * two);
    if (two == 1) {
    document.getElementById('thefour').innerHTML+='<td style="border:2px solid green;">' + numberih(ih, startnum) + '</td>';
    startnum+=eval(one * two);
    }
    document.getElementById('thefour').innerHTML+='<td style="border:2px solid green;">' + numberih(ih, startnum) + '</td>';
    startnum+=eval(one * two);
    }
    //}
    gd='' + numberih(ih, startnum);
    document.getElementById('score').innerHTML='Score: ' + score + '/' + goes + '';
  }
  
  function smsit() {
    var smsn=prompt('Please enter SMS number to send to', '');
    if (smsn == null) { smsn=''; }
    if (smsn.trim() != '' && pluss != '') {
    document.getElementById('aemail').href='sms:' + smsn + '&' + document.getElementById('aemail').href.split(':')[1].split('&')[1].split('%3D')[0] + '%3D' + pluss;
    document.getElementById('aemail').click();
    }
  }
  
  function emailit() {
    var emailn=prompt('Please enter email address to send to', '');
    if (emailn == null) { emailn=''; }
    if (emailn.indexOf('@') != -1 && pluss != '') {
    document.getElementById('aemail').href='mailto:' + emailn + '?subject=Number%20Sequence%20Game&' + document.getElementById('aemail').href.split(':')[1].split('&')[1].split('%3D')[0] + '%3D' + pluss;
    document.getElementById('aemail').click();
    }
  }
  
</script>
</head>
<body onload="setup();" onclick="if (!istart) { istart=true; setInterval(tadd, 1000); }">
<h1>Number Sequence Game   <a title='Email on these same numbers' onclick="emailit();" style="text-decoration:none;cursor:pointer;">📧</a> <a title='SMS on these same numbers' onclick="smsit();" style="text-decoration:none;cursor:pointer;">📟</a></h1>
<h3>RJM Programming - March, 2023</h3>
<h4>Thanks to Dr Crypton's Mind Benders ... Introduction by Isaac Asimov</h4>
<p>Score 2 for correct number.  Lose a point for incorrect number.  Try to be speedy.</p> 
<p>Seconds Taken (to first correct answer): <span id=isecs>0</span> ... <span id=score>Score: 0/0 </span></p>
<table style=width:40%;><tr id=thefour></tr></table>
<p>Next Number in Sequence: <input type=text style=display:inline-block; value='0' id=mynum></input>  <button id=bchk onclick="checkit(document.getElementById('icard'));" style=background-color:yellow;>Check</button> <button onclick="score--; goes++; populate();" style=background-color:yellow;>Redeal</button></p>
<hr></hr>
<details id=hint><summary id=mysummary>Hint(s) ...</summary>
To determine the number there is a constant number and a changing number involved in determining it ... <button onclick="document.getElementById('hint2').style.display='block';">then</button> ...
<div id=hint2 style=display:none;><br> ... the changing number linearly changes  ... <button onclick="document.getElementById('hint3').style.display='block';">and so</button> ...</div>
<div id=hint3 style=display:none;><br> ... the answer we are after is not the constant number.</div>
</details>
<a target=_blank href='mailto:?subject=Number%20Sequence%20Game&body=https%3A%2F%2Fwww.rjmprogramming.com.au%2FHTMLCSS%2Fnumber_sequence.html%3Fsharing%3D' style=display:none; id=aemail>Email</a>
</body>
</html>