<html>
<head>
<title>Sudoku - RJM Programming - December 2022 - Sudoku</title>
<style>
.bright { border-right: 5px solid blue; }
.bbottom { border-bottom: 5px solid blue; }
td { font-size: 24px; width: 11%; height: 9%; text-align: center; vertical-align: middle; }
select { -webkit-appearance: none; font-size: 24px; padding: 1 1 1 1; border: 1px solid transparent; background-image: conic-gradient(pink, hotpink, lightpink); }
#smode { background-image: conic-gradient(yellow, lightyellow, orange); padding: 3 3 3 3; border-radius: 40px; }
th { text-align: left; vertical-align: top; }
textarea { width: 95%; background-image: linear-gradient(rgba(255,255,0,0.5) 18px, white 8%); }
input { width: 95%; }
button { -webkit-appearance: none; border-radius: 10px; }
body { background-image: linear-gradient(to bottom right, rgb(255,255,255), rgb(224, 255, 255),rgb(175, 238, 238), rgb(173, 216, 230),rgb(135, 206, 235),rgb(135, 206, 250),rgb(0, 191, 255),rgb(30, 144, 255),rgb(100, 149, 237),rgb(123, 104, 238),rgb(65, 105, 225),rgb(0, 0, 255),rgb(0, 0, 205),rgb(0, 0, 139),rgb(0, 0, 128),rgb(25, 25, 112)); }
</style>
<script type='text/javascript'>
var hrecs=['','','','','','','','',''];
var lines=['','','','','','','','',''];
var squares=['','','','','','','','',''];
var mustbeguessed=location.search.split('mustbeguessed=')[1] ? decodeURIComponent(location.search.split('mustbeguessed=')[1].split('&')[0]) : '';
var mustnotbeguessed=location.search.split('mustnotbeguessed=')[1] ? decodeURIComponent(location.search.split('mustnotbeguessed=')[1].split('&')[0]) : '';
var gls=getls();
var stemp="<select data-answer=\" \" id=xxx><option value=\" \"> </option><option value='1'>" + ((typeof emj === 'function') ? emj(1) : '1') + "</option><option value='2'>" + ((typeof emj === 'function') ? emj(2) : '2') + "</option><option value='3'>" + ((typeof emj === 'function') ? emj(3) : '3') + "</option><option value='4'>" + ((typeof emj === 'function') ? emj(4) : '4') + "</option><option value='5'>" + ((typeof emj === 'function') ? emj(5) : '5') + "</option><option value='6'>" + ((typeof emj === 'function') ? emj(6) : '6') + "</option><option value='7'>" + ((typeof emj === 'function') ? emj(7) : '7') + "</option><option value='8'>" + ((typeof emj === 'function') ? emj(8) : '8') + "</option><option value='9'>" + ((typeof emj === 'function') ? emj(9) : '9') + "</option></select>";
var okay=false;
var goes=0;
var easyarr=',3,4,7,10,12,14,15,19,20,27,28,29,30,32,34,39,41,44,45,49,51,52,55,57,59,61,67,68,70,71,74,75,76,80,';
var hardarr=',1,5,8,9,13,19,21,28,33,36,37,39,43,49,52,54,61,62,63,67,69,70,72,80,';
var ipuzzle=-1;
var puzzles=[
'684159732751832946923674185192365874845217693367498251239746518516983427478521369',
'436128759951746283872359416785914362213675894694283571528491637167532948349867125',
'647538192953261478281497653865729314394185267712643985128974536576312849439856721',
'974613528583427691612598734135976842867142953249385167351864279428759316796231485',
'271456893856139724349827156638294517925371468417685239183942675592768341764513982',
'842359761137684952956271384679138425523467198481592673795813246364725819218946537',
'765293481124786359839514267257138946916425738348679125681347592492851673573962814',
'167534289589712463324896571892367154471925836635148927748651392253479618916283745',
'731265894645983172829471536417639258263854719598127463354792681982516347176348925',
'253947168967831254481562937749653821625418379138279645512786493876394512394125786',
'615927438478563291293184765136452879957318624842796153729831546361245987584679312',
(location.search.split('thegame=')[1] ? decodeURIComponent(location.search.split('thegame=')[1].split('&')[0]) : '485719362937264815612583794269456173378126549154937628543672981896341257721895436')];

if (puzzles[eval(-1 + puzzles.length)] != '485719362937264815612583794269456173378126549154937628543672981896341257721895436') {
ipuzzle=eval(-1 + puzzles.length); //Math.floor(Math.random() * puzzles.length);
}

function emj(innum) {
return '&#' + eval(48 + eval('' + innum)) + ';️⃣';
}

function dependingdo(ans, iqs) {
var jqs=eval(1 + eval('' + iqs));
var eans=ans;
if (typeof emj === 'function') { eans=emj(ans); }
if (document.URL.indexOf('hard=') != -1) { // hard
document.getElementById('smode').value='hard';
if (hardarr.indexOf(',' + iqs + ',') != -1 || document.URL.indexOf('extremelyeasy=') != -1) {
return eans + stemp.replace('xxx','s' + iqs).replace(' value=" "',' value="' + ans + '"').replace(' data-answer=" "',' style=display:none; data-answer="' + ans + '"').replace('>' + eans + '<',' selected>' + eans + '<').replace('>', ' disabled>');
} else {
return stemp.replace('xxx','s' + iqs).replace(' data-answer=" "',' data-answer="' + ans + '"'); //.replace('>' + ans + '<',' selected>' + ans + '<').replace('>', ' disabled>');
}
} else if (mustbeguessed.trim() != '' && mustnotbeguessed.trim() != '') {
document.getElementById('smode').value='tailored';
if (((',' + mustbeguessed.trim() + ',').indexOf(',' + jqs + ',') == -1 || (',' + mustnotbeguessed.trim() + ',').indexOf(',' + jqs + ',') != -1) || document.URL.indexOf('extremelyeasy=') != -1) {
return eans + stemp.replace('xxx','s' + iqs).replace(' value=" "',' value="' + ans + '"').replace(' data-answer=" "',' style=display:none; data-answer="' + ans + '"').replace('>' + eans + '<',' selected>' + eans + '<').replace('>', ' disabled>');
} else {
return stemp.replace('xxx','s' + iqs).replace(' data-answer=" "',' data-answer="' + ans + '"'); //.replace('>' + ans + '<',' selected>' + ans + '<').replace('>', ' disabled>');
}
} else if (mustbeguessed.trim() != '' && mustnotbeguessed.trim() == '') {
document.getElementById('smode').value='tailored';
if ((',' + mustbeguessed.trim() + ',').indexOf(',' + jqs + ',') == -1 || document.URL.indexOf('extremelyeasy=') != -1) {
return eans + stemp.replace('xxx','s' + iqs).replace(' value=" "',' value="' + ans + '"').replace(' data-answer=" "',' style=display:none; data-answer="' + ans + '"').replace('>' + eans + '<',' selected>' + eans + '<').replace('>', ' disabled>');
} else {
return stemp.replace('xxx','s' + iqs).replace(' data-answer=" "',' data-answer="' + ans + '"'); //.replace('>' + ans + '<',' selected>' + ans + '<').replace('>', ' disabled>');
}
} else if (mustbeguessed.trim() == '' && mustnotbeguessed.trim() != '') {
document.getElementById('smode').value='tailored';
if ((',' + mustnotbeguessed.trim() + ',').indexOf(',' + jqs + ',') != -1 || document.URL.indexOf('extremelyeasy=') != -1) {
return eans + stemp.replace('xxx','s' + iqs).replace(' value=" "',' value="' + ans + '"').replace(' data-answer=" "',' style=display:none; data-answer="' + ans + '"').replace('>' + eans + '<',' selected>' + eans + '<').replace('>', ' disabled>');
} else {
return stemp.replace('xxx','s' + iqs).replace(' data-answer=" "',' data-answer="' + ans + '"'); //.replace('>' + ans + '<',' selected>' + ans + '<').replace('>', ' disabled>');
}
} else { // easy
if (easyarr.indexOf(',' + iqs + ',') != -1 || document.URL.indexOf('extremelyeasy=') != -1) {
return eans + stemp.replace('xxx','s' + iqs).replace(' value=" "',' value="' + ans + '"').replace(' data-answer=" "',' style=display:none; data-answer="' + ans + '"').replace('>' + eans + '<',' selected>' + eans + '<').replace('>', ' disabled>');
} else {
return stemp.replace('xxx','s' + iqs).replace(' data-answer=" "',' data-answer="' + ans + '"'); //.replace('>' + ans + '<',' selected>' + ans + '<').replace('>', ' disabled>');
}
}
}

function newgame() {
var j, k, tds=document.getElementsByTagName('td'), m=-1, isq=-1;
hrecs=['','','','','','','','',''];
lines=['','','','','','','','',''];
squares=['','','','','','','','',''];
for (var i=0; i<tds.length; i++) {
if (eval(i % 9) == 0) { m++; }
if (eval(i % 3) == 0) { isq++; }
if (eval(i % 9) == 0) { isq=eval(Math.floor(eval(i / 27)) * 3); }
//console.log('i=' + i + ' leads to isq=' + isq);
hrecs[i]='';
if (eval('' + ipuzzle) >= 0) {
j=eval(puzzles[ipuzzle].substring(i).substring(0,1));
} else {
j=Math.min(9,eval(Math.floor(Math.random() * 9) + 1));
}
k=0;
while (hrecs[m].indexOf('' + j) != -1 || lines[eval(i % 9)].indexOf('' + j) != -1 || squares[isq].indexOf('' + j) != -1) {
j=Math.min(9,eval(Math.floor(Math.random() * 9) + 1));
k++;
if (eval('' + k) > 30) { goes++; if (1 == 2) { document.title+='' + goes; } if (1 == 11) { console.log(goes + ' at i=' + i + ' hrecs[0]=' + hrecs[0] + ' hrecs[1]=' + hrecs[1] + ' hrecs[2]=' + hrecs[2]); } return false; }
}
tds[i].title='Square number ' + eval(1 + eval('' + i));
tds[i].innerHTML=dependingdo('' + j, i);
hrecs[m]+='' + j;
lines[eval(i % 9)]+='' + j;
squares[isq]+='' + j;
}
//alert(squares[0] + ' ... ' + squares[1]);
document.getElementById('mytable').style.cursor='pointer';
return true;
}

function checksels() {
var isok=true;
var sels=document.getElementsByTagName('select');
for (var jj=0; jj<sels.length; jj++) {
if (('' + sels[jj].id) != 'smode') {
if (sels[jj].value.trim() == '') { alert('Not solved yet'); return false; }
if (typeof retnc === 'function') {
if (sels[jj].outerHTML.indexOf(' data-answer="' + retnc(sels[jj].value) + '"') == -1) { alert('Not solved yet'); return false; }
} else {
if (sels[jj].outerHTML.indexOf(' data-answer="' + sels[jj].value + '"') == -1) { alert('Not solved yet'); return false; }
}
}
}
alert('Congratulations!');
return true;
}

function askmaybe(indef) {
var tans='';
var tpars='';
if (indef.indexOf('tailored=') == 0) {
tans=prompt('Using square numbers of 9x9 grid from 1 to 81, specify in comma separated list, where prefixed by minus would be pre-answered else represents squares to be answered, for Sudoku game to follow. To remember for the future involve leading or trailing spaces. Involve an x to delete any pre-existing saved tailored Sudoku game configurations.', '');
if (tans == null) { tans=''; }
var atansarr=tans.replace(/x/g,'').replace(/X/g,'').split(',');
if (gls!= '' && tans.toLowerCase().indexOf('x') != -1) {
window.localStorage.removeItem('sudokudefs');
gls='';
}
for (var it=0; it<atansarr.length; it++) {
if (('' + atansarr[it]).trim() != '') {
if (('' + atansarr[it] + ' ').indexOf('-') == 0) {
if (tpars.indexOf('mustnotbeguessed=') == -1) { tpars+='&mustnotbeguessed=' + atansarr[it].trim().substring(1); } else { tpars=tpars.replace('&mustnotbeguessed=', '&mustnotbeguessed=' + atansarr[it].trim().substring(1) + ','); }
} else {
if (tpars.indexOf('mustbeguessed=') == -1) { tpars+='&mustbeguessed=' + atansarr[it].trim(); } else { tpars=tpars.replace('&mustbeguessed=', '&mustbeguessed=' + atansarr[it].trim() + ','); }
}
}
}
if (tpars != '') {
if (tans.trim() != tans) {
if (getls() != '') {
window.localStorage.removeItem('sudokudefs');
}
window.localStorage.setItem('sudokudefs', encodeURIComponent(tpars.substring(1)));
}
return tpars.substring(1);
}
}
return indef;
}

function getls() {
return decodeURIComponent(('' + window.localStorage.getItem('sudokudefs')).replace(/^undefined/g,'').replace(/^null/g,''));
}

function checkls() {
if (gls != '' && document.URL.indexOf('?') == -1) {
location.href=document.URL.split('#')[0].split('?')[0] + '?' + gls;
}
if (document.URL.indexOf('/sudoku.htm') == -1) {
document.getElementById('ares').style.textDecoration='none';
}
}
</script>
</head>
<body style=" background-image: linear-gradient(to bottom right, rgb(255,255,255), rgb(224, 255, 255),rgb(175, 238, 238),rgb(173, 216, 230),rgb(135, 206, 235),rgb(135, 206, 250),rgb(0, 191, 255),rgb(30, 144, 255),rgb(100, 149, 237),rgb(123, 104, 238),rgb(65, 105, 225),rgb(0, 0, 255),rgb(0, 0, 205),rgb(0, 0, 139),rgb(0, 0, 128),rgb(25, 25, 112)); " onload="checkls(); while (!okay) { okay=newgame(); }">
<table style="width:95%;"><tr id="ourrow"><th id="onleft">
<h1>Sudoku <select id="smode" onchange="location.href=document.URL.split('?')[0].split('#')[0] + '?' + askmaybe(this.value + '=' + this.value);"><option value='easy'>Easy</option><option value=hard>Hard</option><option value='tailored'>Tailored</option></select></h1>
<h3>RJM Programming <a id=ares href='./index.php' title='Collaboration and sharing'>-</a> December, 2022 <span id="semojis"></span></h3>
</th><tH id=toright style=display:none;><input onkeydown="if (typeof settyping === 'function') { settyping(); }" onblur="if (typeof typingunset === 'function') { typingunset(); } iblur(this);" type=text placeholder="Optionally chat here ..." id=sudokui value=""></input><br><br><textarea id=tais rows=3 cols=80 value=""></textarea></tH></tr></table>

<table id=mytable style='width:95%;height:81%;cursor:progress;background-color:lightyellow;border-radius:10px;' border=5>
<tr id=tr1of9><td id=td11></td><td id=td21></td><td id=td31 class=bright></td><td id=td41></td><td id=td51></td><td id=td61 class=bright></td><td id=td71></td><td id=td81></td><td id=td91></td></tr>
<tr id=tr2of9><td id=td12></td><td id=td22></td><td id=td32 class=bright></td><td id=td42></td><td id=td52></td><td id=td62 class=bright></td><td id=td72></td><td id=td82></td><td id=td92></td></tr>
<tr id=tr3of9><td id=td13 class=bbottom></td><td id=td23 class=bbottom></td><td id=td33 class="bright bbottom"></td><td id=td43 class=bbottom></td><td id=td53 class=bbottom></td><td id=td63 class="bright bbottom"></td><td id=td73 class=bbottom></td><td id=td83 class=bbottom></td><td id=td93 class=bbottom></td></tr>
<tr id=tr4of9><td id=td14></td><td id=td24></td><td id=td34 class=bright></td><td id=td44></td><td id=td54></td><td id=td64 class=bright></td><td id=td74></td><td id=td84></td><td id=td94></td></tr>
<tr id=tr5of9><td id=td15></td><td id=td25></td><td id=td35 class=bright></td><td id=td45></td><td id=td55></td><td id=td65 class=bright></td><td id=td75></td><td id=td85></td><td id=td95></td></tr>
<tr id=tr6of9><td id=td16 class=bbottom></td><td id=td26 class=bbottom></td><td id=td36 class="bright bbottom"></td><td id=td46 class=bbottom></td><td id=td56 class=bbottom></td><td id=td66 class="bright bbottom"></td><td id=td76 class=bbottom></td><td id=td86 class=bbottom></td><td id=td96 class=bbottom></td></tr>
<tr id=tr7of9><td id=td17></td><td id=td27></td><td id=td37 class=bright></td><td id=td47></td><td id=td57></td><td id=td67 class=bright></td><td id=td77></td><td id=td87></td><td id=td97></td></tr>
<tr id=tr8of9><td id=td18></td><td id=td28></td><td id=td38 class=bright></td><td id=td48></td><td id=td58></td><td id=td68 class=bright></td><td id=td78></td><td id=td88></td><td id=td98></td></tr>
<tr id=tr9of9><td id=td19></td><td id=td29></td><td id=td39 class=bright></td><td id=td49></td><td id=td59></td><td id=td69 class=bright></td><td id=td79></td><td id=td89></td><td id=td99></td></tr>
</table>
<br><button style=background-color:yellow; onclick=checksels();>Check My Answers</button> <button style=background-color:orange; onclick='location.href=document.URL;'>New Game</button>
</body>
</html>