Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/public/blog/wp-includes/kses.php on line 932

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/public/blog/wp-includes/kses.php on line 933

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/public/blog/wp-includes/kses.php on line 932

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/public/blog/wp-includes/kses.php on line 933

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/public/blog/wp-includes/kses.php on line 932

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/public/blog/wp-includes/kses.php on line 933

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/public/blog/wp-includes/kses.php on line 932

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/public/blog/wp-includes/kses.php on line 933

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/public/blog/wp-includes/kses.php on line 932

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/public/blog/wp-includes/kses.php on line 933

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/public/blog/wp-includes/kses.php on line 932

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/public/blog/wp-includes/kses.php on line 933

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/public/blog/wp-includes/kses.php on line 932

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/public/blog/wp-includes/kses.php on line 933

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/public/blog/wp-includes/kses.php on line 932

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/public/blog/wp-includes/kses.php on line 933

Just Widgets Blog

On technology and points of interest on the web…

 

JavaScript Solver for Wei-Hwa’s Puzzle #3

Filed under: Code, Google, Web Tech — June 14, 2006 @ 10:36 pm

I’ve written a javascript program (latest version) which finds the solution to Wei-Hwa’s Puzzle Challenge #3 (formerly the Da Vinci Code Quest module). You can add his puzzle module to your Google Homepage here: fusion.google.com/add… or if you don’t want to sign up to get a Personalized Google Homepage, the latest puzzle is being posted on a third-party web page here: solvepuzzles.googlepages.com/.
If you get stumped, come back here and have my program find the answer for you.

For a little while, I tried solving puzzle #3 manually but it was getting a little frustrating as others have commented. Once I realized that there is a simple rule involving the possible distances (I don’t want to spoil it here), I actually thought it would take only a little longer to code up a solver compared to manually solving it by trial-and-error. Well, 4 days later, I proved myself wrong. Since I worked on it part-time over the weekend, it probably took about 2.5; days total. I guess I shouldn’t feel that bad since I was rusty with JavaScript and it was a fun refresher (first time using a JavaScript debugger too). Hey, at least I’m in good company, given that a web guru at Yahoo! took about as long to get a web version of Tetris done.

For those who prefer C code rather than JavaScript, a Rubik’s Cube expert, Dave Barr, has posted a C program that solves it.

I would like to add some code to show the progress on the puzzle board. It’s just an HTML table changed through .style and .nodeValue properties. It would be a nice piece of animated user feedback. I do constantly update the puzzle board in the code but for some reason the browser chooses not to display the updates and only shows the final solution, no intermediates. Actually, this is true for Mozilla/Firefox and Internet Explorer 6 but the lesser known, yet impressive Opera Web Browser does actually show the progress in solving the puzzle - and it still solves it faster than Mozilla! So are Mozilla and IE just buffering their displays for too long? I tried the extremely inefficient loop-that-counts-to-100,000 technique to slow things down but that didn’t help. Then I did a few tests with window.setTimeout() and although it didn’t spike CPU usage to 100% like the previous loop method, it still didn’t change anything - the puzzle board stayed blank and then displayed the full solution. Try it (latest version) for yourself and you’ll see what I mean. If anyone has a suggestion, please post a comment or contact me: george@justwidgets.com

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.