b.innerHTML += '<span id=play></span><style>#c{display:none}div{width:25px;float:left;border:1px solid #000;text-align:center;margin:1px}.b{border-color:#FFF}.r{background:#A00;color:#FFF}</style>';l=localStorage;q=l.length==0?3:l.getItem("q")|0;n=[];function m(){b.style.width=q*29+"px";w=q*q-1;x=w;n=[];for(i=0;i<w;i++){r=(Math.random()*w)|0;t=n[r]?n[r]:r+1;n[r]=n[i]?n[i]:i+1;n[i]=t}y=0;for(i=0;o=n[i],i<w;i++)for(j=i+1;p=n[j],j<w;j++)y+=p<o?1:0;if(y%2==1)m();n[w]=0;d()}function d(){p=document.getElementById("play");p.innerHTML="";for(i in n){o=n[i]==0?' ':n[i];p.innerHTML+="<div "+c(o)+">"+o+"</div>"}}function s(o){a=x;if(o==0)x--;if(o==1)x-=q;if(o==2)x++;if(o==3)x+=q;t=n[a];n[a]=n[x];n[x]=t;d()}addEventListener("keydown",function(e){k=e.keyCode-37;if((k==0&&x%q>0)||(k==1&&x>=q)||(k==2&&x%q<q-1)||(k==3&&x<q*q-q))s(k);if(x==w){for(i=0;i<w-1;i++){if(n[i]>n[i+1])return;}alert("YOU WIN!");l.setItem("q",++q);m()}},!1);function c(o){if(o%2==1)return 'class="r"';if(o==" ")return 'class=b';return ""}m()
Yi5pbm5lckhUTUwgKz0gJzxzcGFuIGlkPXBsYXk+PC9zcGFuPjxzdHlsZT4jY3tkaXNwbGF5Om5vbmV9ZGl2e3dpZHRoOjI1cHg7ZmxvYXQ6bGVmdDtib3JkZXI6MXB4IHNvbGlkICMwMDA7dGV4dC1hbGlnbjpjZW50ZXI7bWFyZ2luOjFweH0uYntib3JkZXItY29sb3I6I0ZGRn0ucntiYWNrZ3JvdW5kOiNBMDA7Y29sb3I6I0ZGRn08L3N0eWxlPic7bD1sb2NhbFN0b3JhZ2U7cT1sLmxlbmd0aD09MD8zOmwuZ2V0SXRlbSgicSIpfDA7bj1bXTtmdW5jdGlvbiBtKCl7Yi5zdHlsZS53aWR0aD1xKjI5KyJweCI7dz1xKnEtMTt4PXc7bj1bXTtmb3IoaT0wO2k8dztpKyspe3I9KE1hdGgucmFuZG9tKCkqdyl8MDt0PW5bcl0/bltyXTpyKzE7bltyXT1uW2ldP25baV06aSsxO25baV09dH15PTA7Zm9yKGk9MDtvPW5baV0saTx3O2krKylmb3Ioaj1pKzE7cD1uW2pdLGo8dztqKyspeSs9cDxvPzE6MDtpZih5JTI9PTEpbSgpO25bd109MDtkKCl9ZnVuY3Rpb24gZCgpe3A9ZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoInBsYXkiKTtwLmlubmVySFRNTD0iIjtmb3IoaSBpbiBuKXtvPW5baV09PTA/JyZuYnNwOyc6bltpXTtwLmlubmVySFRNTCs9IjxkaXYgIitjKG8pKyI+IitvKyI8L2Rpdj4ifX1mdW5jdGlvbiBzKG8pe2E9eDtpZihvPT0wKXgtLTtpZihvPT0xKXgtPXE7aWYobz09Mil4Kys7aWYobz09Myl4Kz1xO3Q9blthXTtuW2FdPW5beF07blt4XT10O2QoKX1hZGRFdmVudExpc3RlbmVyKCJrZXlkb3duIixmdW5jdGlvbihlKXtrPWUua2V5Q29kZS0zNztpZigoaz09MCYmeCVxPjApfHwoaz09MSYmeD49cSl8fChrPT0yJiZ4JXE8cS0xKXx8KGs9PTMmJng8cSpxLXEpKXMoayk7aWYoeD09dyl7Zm9yKGk9MDtpPHctMTtpKyspe2lmKG5baV0+bltpKzFdKXJldHVybjt9YWxlcnQoIllPVSBXSU4hIik7bC5zZXRJdGVtKCJxIiwrK3EpO20oKX19LCExKTtmdW5jdGlvbiBjKG8pe2lmKG8lMj09MSlyZXR1cm4gJ2NsYXNzPSJyIic7aWYobz09IiZuYnNwOyIpcmV0dXJuICdjbGFzcz1iJztyZXR1cm4gIiJ9bSgp
b.innerHTML += '<span id=play></span><style>#c {display:none}div {width:25px;float:left;border:1px solid #000;text-align:center;margin:1px}.b {border-color:#FFF}.r {background:#A00;color:#FFF}</style>';
l=localStorage;
q=l.length==0?3:l.getItem("q")|0;
n=[];
function m() {
b.style.width=q*29"px"; // TILES ARE WRAPPED USING CSS float:left WITH A FIXED WIDTH
w=q*q-1;
x=w;
n=[];
for(i=0;i<w;i++) { //SHUFFLE BY SWITCHING EACH SPOT WITH A RANDOM LOCATION
r=(Math.random()*w)|0;
t=n[r]?n[r]:r+1; // IF A LOCATION ISN'T SET YET, USE i+1
n[r]=n[i]?n[i]:i+1; //...SINCE CORRECT ORDER WOULD BE [1,2,3,4,5..
n[i]=t
}
//SOLVABILITY CHECK
y=0; // IF THE TOTAL COUNT...
for(i=0;o=n[i],i<w;i++) //...FOR EACH NUMBER...
for(j=i+1;p=n[j],j<w;j++) //...OF NUMBERS...
y+=p<o?1:0; //...LESS THAN ITSELF
if(y%2==1) //...IS ODD...
m(); //...THE PUZZLE IS UNSOLVABLE, RESCRAMBLE
n[w]=0; // src: http://tinyurl.com/3kv87o5
d()
}
//DRAW TILES
function d() {
p=document.getElementById("play");
p.innerHTML="";
for(i in n) {
o=n[i]==0?' ':n[i]; // 0 == BLANK TILE
p.innerHTML+="<div "+c(o)+">"+o+"</div>" // ADD TILE
}
}
//SWITCH TWO TILES
function s(o) {
a=x;
if(o==0)x--; // LEFT
if(o==1)x-=q; // UP
if(o==2)x++; // RIGHT
if(o==3)x+=q; // DOWN
t=n[a];
n[a]=n[x];
n[x]=t;
d()
}
addEventListener("keydown",function(e) {
k=e.keyCode-37;
if((k==0&&x%q>0)||(k==1&&x>=q)||(k==2&&x%q<q-1)||(k==3&&x<q*q-q))s(k);
if(x==w) { // IF THE BLANK TILE IS IN THE BOTTOM RIGHT
for(i=0;i<w-1;i++) {
if(n[i]>n[i+1])return; // WE HAVEN'T WON IF ANY TILE IS BIGGER THAN THE ONE NEXT TO IT
}
alert("YOU WIN!"); // *kazoo!*
l.setItem("q",++q); //SAVE PROGRESS AND LOAD NEXT LEVEL
m()
}
},!1);
//RETURNS A STYLE CLASS IF ONE IS NECESSARY
function c(o) {
if(o%2==1) return 'class="r"'; //ODDS ARE RED
if(o==" ") return 'class="b"'; //BLANK HAS NO BORDER
return ""
}
m() //LET'S DO IT