Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,152,467 members, 7,816,092 topics. Date: Friday, 03 May 2024 at 04:25 AM

Nairaland Programming Contest (8-Puzzle) - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Nairaland Programming Contest (8-Puzzle) (1833 Views)

Female OAU Graduate Wins N1m In iROKOtv Programming Contest / Sayo Oladeji Wins N1m In Programming Contest (photos) / Nairaland Programming Index(Topic Ordered Listing of Programming Board Threads). (2) (3) (4)

(1) (Reply) (Go Down)

Nairaland Programming Contest (8-Puzzle) by Nobody: 4:56pm On Nov 04, 2010
[url]http://www.ugcs.caltech.edu/~bokonobo/puzzle/puzzle.xhtml[/url]

Hello, click on the above link for the first contest. Hopefully it all goes well. You are free to bother me with questions.



Update:
Mr Beaf has called my attention to a security warning that may occur if you try to access the Caltech network from outside. I am totally confused as to why this is since we have one the best secured networks in the world. Anyway, if you encounter such a warning, I can assure you that all is well, but if you are the cynical type you may download the attached file puzzle.png, which is actually a zip file(NL does not let you attach zip files). Change the extension to .zip and uncompress, then open the puzzle.xhtml file in your browser.

Re: Nairaland Programming Contest (8-Puzzle) by lojik(m): 3:07am On Nov 05, 2010
Copy and save the code below as html file, then run.


<style type="text/css">
.square{width:100px; height:100px; font-size:72; font-weight:bolder;}
</style>
<div align="center">
<table border="1">
<tr>
<td align="center" id="s11" class="square">1</td>
<td align="center" id="s12" class="square">2</td>
<td align="center" id="s13" class="square">3</td>
</tr>
<tr>
<td align="center" id="s21" class="square">4</td>
<td align="center" id="s22" class="square">5</td>
<td align="center" id="s23" class="square">6</td>
</tr>
<tr>
<td align="center" id="s31" class="square">7</td>
<td align="center" id="s32" class="square">8</td>
<td align="center" id="s33" class="square">&nbsp;</td>
</tr>
</table>

<table>
<tr><td></td><td><a href="#" onclick="move('U'); return false;">U</a></td><td></td></tr>
<tr><td><a href="#" onclick="move('L'); return false;">L</a></td><td></td><td><a href="#" onclick="move('R'); return false;">R</a></td></tr>
<tr><td></td><td>
<a href="#" onclick="move('D'); return false;">grin</a></td><td></td></tr>
</table>



<a href="#" onclick="makeArray(); return false;">Create array</a>
<a href="#" onclick="loadArray (); return false;">Load array</a>


<span id="moves">Successful moves: </span>


<span id="arrayz"></span>
</div>


<script type="text/javascript">
function move (dir){
if(dir=="grin"wink{axis="y";step=1;}
if(dir=="U"wink{axis="y";step=-1}
if(dir=="R"wink{axis="x";step=1}
if(dir=="L"wink{axis="x";step=-1}
found=false;
for(x=1; x<=3; x++){
for(y=1;y<=3; y++){
pos = 's'+x+y;
if(parseInt( document.getElementById(pos).innerHTML) > 0){
} else {
xx = x + step;
yy = y + step;
if(!found && axis=="y" && xx >= 1 && xx <=3){
document.getElementById(pos).innerHTML = document.getElementById('s'+xx+y).innerHTML;
document.getElementById('s'+xx+y).innerHTML = "&nbsp;";
found=true;
break;
}
if(!found && axis=="x" && yy >= 1 && yy <=3){
document.getElementById(pos).innerHTML = document.getElementById('s'+x+yy).innerHTML;
document.getElementById('s'+x+yy).innerHTML = "&nbsp;";
found=true;
break;
}
}

}
}
if(found) document.getElementById("moves"wink.innerHTML = document.getElementById("moves"wink.innerHTML + " " + dir;
else alert("The space tile cannot move out of the bounds of the array!"wink;
}


function makeArray (){
tempArray = new Array();
count=0;
for(x=1; x<=3; x++){
for(y=1;y<=3; y++){
tempArray[count] = "'"+document.getElementById('s'+x+y).innerHTML+"'";
count++;
}
}
document.getElementById("arrayz"wink.innerHTML = "["+tempArray.join(", "wink+"]";
}




function loadArray (){
var vars = prompt("Specify comma separated array values", "3,1,2,4,,5,6,7,8"wink;
tempArray = vars.split(',');
count=0;
for(x=1; x<=3; x++){
for(y=1;y<=3; y++){
document.getElementById('s'+x+y).innerHTML = tempArray[count];
count++;
}
}
}
</script>
Re: Nairaland Programming Contest (8-Puzzle) by Nobody: 4:25am On Nov 05, 2010
lojik:

Copy and save the code below as html file, then run.


<style type="text/css">
.square{width:100px; height:100px; font-size:72; font-weight:bolder;}
</style>
<div align="center">
<table border="1">
<tr>
   <td align="center" id="s11" class="square">1</td>
   <td align="center" id="s12" class="square">2</td>
   <td align="center" id="s13" class="square">3</td>
</tr>
<tr>
   <td align="center" id="s21" class="square">4</td>
   <td align="center" id="s22" class="square">5</td>
   <td align="center" id="s23" class="square">6</td>
</tr>
<tr>
   <td align="center" id="s31" class="square">7</td>
   <td align="center" id="s32" class="square">8</td>
   <td align="center" id="s33" class="square">&nbsp;</td>
</tr>
</table>

<table>
<tr><td></td><td><a href="#" onclick="move('U'); return false;">U</a></td><td></td></tr>
<tr><td><a href="#" onclick="move('L'); return false;">L</a></td><td></td><td><a href="#" onclick="move('R'); return false;">R</a></td></tr>
<tr><td></td><td>
<a href="#" onclick="move('D'); return false;">grin</a></td><td></td></tr>
</table>



<a href="#" onclick="makeArray(); return false;">Create array</a>
<a href="#" onclick="loadArray (); return false;">Load array</a>


<span id="moves">Successful moves: </span>


<span id="arrayz"></span>
</div>


<script type="text/javascript">
function move (dir){
if(dir=="grin"wink{axis="y";step=1;}
if(dir=="U"wink{axis="y";step=-1}
if(dir=="R"wink{axis="x";step=1}
if(dir=="L"wink{axis="x";step=-1}
found=false;
for(x=1; x<=3; x++){
for(y=1;y<=3; y++){
     pos = 's'+x+y;
   if(parseInt( document.getElementById(pos).innerHTML) > 0){
   } else {
   xx = x + step;
   yy = y + step;
   if(!found && axis=="y" && xx >= 1 && xx <=3){
      document.getElementById(pos).innerHTML = document.getElementById('s'+xx+y).innerHTML;
      document.getElementById('s'+xx+y).innerHTML = "&nbsp;";
      found=true;
      break;
   }
   if(!found && axis=="x" && yy >= 1 && yy <=3){
      document.getElementById(pos).innerHTML = document.getElementById('s'+x+yy).innerHTML;
      document.getElementById('s'+x+yy).innerHTML = "&nbsp;";
      found=true;
      break;
   }
   }

}
}
if(found) document.getElementById("moves"wink.innerHTML = document.getElementById("moves"wink.innerHTML + " " + dir;
else alert("The space tile cannot move out of the bounds of the array!"wink;
}


function makeArray (){
tempArray = new Array();
count=0;
for(x=1; x<=3; x++){
for(y=1;y<=3; y++){
tempArray[count] = "'"+document.getElementById('s'+x+y).innerHTML+"'";
count++;
}
}
document.getElementById("arrayz"wink.innerHTML = "["+tempArray.join(", "wink+"]";
}




function loadArray (){
var vars = prompt("Specify comma separated array values", "3,1,2,4,,5,6,7,8"wink;
tempArray = vars.split(',');
count=0;
for(x=1; x<=3; x++){
for(y=1;y<=3; y++){
document.getElementById('s'+x+y).innerHTML = tempArray[count];
count++;
}
}
}
</script>


Nice job bro!

[s]I got a notification that you posted on this thread, but when I checked for your reply, I couldn't find it. Maybe one of the administrator deleted your post? I don't think so because I perused your profile and found the code you posted.[/s] I wanted to add the functionalities you wrote, but I did not have enough time. Maybe later. But I noticed that you did not solve the puzzle, you only provided a way to play it. I guess that was your intention since I have seen your work, and I was impressed.
Re: Nairaland Programming Contest (8-Puzzle) by Nobody: 7:33am On Nov 05, 2010
@lojik do u know any site where i can learn solving complex maths with programming i lack in that department
Re: Nairaland Programming Contest (8-Puzzle) by xoxogg(f): 10:17am On Nov 05, 2010
I see. You want an 8 puzzle solver angry angry angry its a very common programming problem though i've never attempted it , i'll still try, its about time i also solved it.
Re: Nairaland Programming Contest (8-Puzzle) by lojik(m): 8:56pm On Nov 05, 2010
i have written even an 80 puzzle code in flash/actionscript as game and i felt the problem you posted was simple thats y i left the solution to those who would find it challenging enuf lest i kill the thread early. In a bid to encourage them, i wrote that JS code to help them in solving the puzzle.

@pc guru
I solve a lot of maths related programming problems by using o'level mathematics.
All the Laplace transform and Fourier series i learnt in my B.Sc Engineering has had little or no role to play in my programming, just secondary school maths and little a'level once in a while.

I recommend u properly refresh and understand the logic behind every math topic in the senior secondary school syllabus. You may try to overlook them or underestimate them but believe me, they form the basis of every math problem you will ever face. Focus more on the logic and less on the arithmetics. That will not take u long and i believe its a good start.


This recommendation is on the assumption that u are not into low level programming. At least i know u do more of php, JS and stuff like that.
Re: Nairaland Programming Contest (8-Puzzle) by Nobody: 10:56pm On Nov 05, 2010
lojik:

i have written even an 80 puzzle code in flash/actionscript as game and i felt the problem you posted was simple thats y i left the solution to those who would find it challenging enuf lest i kill the thread early. In a bid to encourage them, i wrote that JS code to help them in solving the puzzle.

I am not disputing your claim that you have solved an 80-puzzle problem, but you have to prove it! Anyone can claim anything. Since this is the first problem I am posting, I thought it should be an easy problem. So far, a lot of people have sent me emails giving me the solutions, but no code! They solved it by hand grin. My goal is not to show that most programmers here are all talk, no action, but to facilitate code sharing, analyzing other programmer's codes, and to see the one that runs fastest. I would be honored if you could send me a solution to the problem.

And trust me bro, I would love for you to kill the thread early grin. It is the not the answers that matter; it is the code. Bring the heat on!
Re: Nairaland Programming Contest (8-Puzzle) by Beaf: 2:12pm On Nov 06, 2010
What is so difficult about copying and pasting the puzzle here? I get security warnings from that link and am losing interest.
Re: Nairaland Programming Contest (8-Puzzle) by lojik(m): 3:11pm On Nov 06, 2010
I'm tired of this NL spam bot. Anyway, read my reply here:
http://pastebin.com/eKYF817V
Re: Nairaland Programming Contest (8-Puzzle) by Nobody: 11:19pm On Nov 06, 2010
Beaf:

What is so difficult about copying and pasting the puzzle here? I get security warnings from that link and am losing interest.

Beaf, I am deeply really sorry for the inconvenience. I do not know how to create such a layout using NL tools, but I have attached the compressed files to this reply; you can download them onto your computer, uncompress them, and view the puzzle.xhtml in your browser.

Change the puzzle.png to puzzle.zip (NL did not let me attach a zip file, so I had to change the extension)

Once again, I am sorry cry

Re: Nairaland Programming Contest (8-Puzzle) by Nobody: 11:25pm On Nov 06, 2010
lojik:

I'm tired of this NL spam bot. Anyway, read my reply here:
http://pastebin.com/eKYF817V

Why do your posts keep vanishing? It seems you have stepped on the toes of the powers that be on NL. grin

Anyway, your solution is correct; I had no doubts about your abilities since I have seen some of your work. We should correspond more often. I will post my solution(code) in three days time.

(1) (Reply)

Web Designing / A 30 Day Coding Challenge (Python) For BEGINNERS / Thread closed.

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 50
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.