AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

sudoku helper
Goto page Previous  1, 2
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
JBensimon



Joined: 16 Nov 2004
Posts: 130
Location: New York

PostPosted: Mon Oct 16, 2006 2:00 am    Post subject: Sudoku Sensei (Beta code) Reply with quote

I'm not really "IM-enabled", slomz, but I'll tell you what: I'll just post the current code (warts and all), subject to a future correction (at which point I'll ask you to burn your copy! Smile). You should note that the automatic solving code is a really tiny recursive routine, so the bulk of the program is to provide the GUI features. I'll zip up the program and a little 1-pixel .bmp file used to provide the highlighting background (to get around the inability to change a text control's background color in AHK).

The code is at http://www.autohotkey.net/~JBensimon/SudokuCode.zip

Here's a screenshot of what the prgram looks like (in manual solving mode): http://www.autohotkey.net/file/index.php?act=img&target=SudokuScreenshot.bmp


Later,

Jacques.[/url]
Back to top
View user's profile Send private message Visit poster's website
slomz



Joined: 03 Sep 2006
Posts: 608
Location: Iowa, U.S.

PostPosted: Mon Oct 16, 2006 2:56 am    Post subject: Reply with quote

That is a very complex script.

Spare time my ass.....:

Code:
InitR(1,2,3,4,5,6,7,8,9,10,19,28,37,46,55,64,73,11,12,20,21)
InitR(2,1,3,4,5,6,7,8,9,11,20,29,38,47,56,65,74,10,12,19,21)
InitR(3,1,2,4,5,6,7,8,9,12,21,30,39,48,57,66,75,10,11,19,20)
InitR(4,1,2,3,5,6,7,8,9,13,22,31,40,49,58,67,76,14,15,23,24)
InitR(5,1,2,3,4,6,7,8,9,14,23,32,41,50,59,68,77,13,15,22,24)
InitR(6,1,2,3,4,5,7,8,9,15,24,33,42,51,60,69,78,13,14,22,23)
InitR(7,1,2,3,4,5,6,8,9,16,25,34,43,52,61,70,79,17,18,26,27)
InitR(8,1,2,3,4,5,6,7,9,17,26,35,44,53,62,71,80,16,18,25,27)
InitR(9,1,2,3,4,5,6,7,8,18,27,36,45,54,63,72,81,16,17,25,26)
InitR(10,11,12,13,14,15,16,17,18,1,19,28,37,46,55,64,73,2,3,20,21)
InitR(11,10,12,13,14,15,16,17,18,2,20,29,38,47,56,65,74,1,3,19,21)
InitR(12,10,11,13,14,15,16,17,18,3,21,30,39,48,57,66,75,1,2,19,20)
InitR(13,10,11,12,14,15,16,17,18,4,22,31,40,49,58,67,76,5,6,23,24)
InitR(14,10,11,12,13,15,16,17,18,5,23,32,41,50,59,68,77,4,6,22,24)
InitR(15,10,11,12,13,14,16,17,18,6,24,33,42,51,60,69,78,4,5,22,23)
InitR(16,10,11,12,13,14,15,17,18,7,25,34,43,52,61,70,79,8,9,26,27)
InitR(17,10,11,12,13,14,15,16,18,8,26,35,44,53,62,71,80,7,9,25,27)
InitR(18,10,11,12,13,14,15,16,17,9,27,36,45,54,63,72,81,7,8,25,26)
InitR(19,20,21,22,23,24,25,26,27,1,10,28,37,46,55,64,73,2,3,11,12)
InitR(20,19,21,22,23,24,25,26,27,2,11,29,38,47,56,65,74,1,3,10,12)
InitR(21,19,20,22,23,24,25,26,27,3,12,30,39,48,57,66,75,1,2,10,11)
InitR(22,19,20,21,23,24,25,26,27,4,13,31,40,49,58,67,76,5,6,14,15)
InitR(23,19,20,21,22,24,25,26,27,5,14,32,41,50,59,68,77,4,6,13,15)
InitR(24,19,20,21,22,23,25,26,27,6,15,33,42,51,60,69,78,4,5,13,14)
InitR(25,19,20,21,22,23,24,26,27,7,16,34,43,52,61,70,79,8,9,17,18)
InitR(26,19,20,21,22,23,24,25,27,8,17,35,44,53,62,71,80,7,9,16,18)
InitR(27,19,20,21,22,23,24,25,26,9,18,36,45,54,63,72,81,7,8,16,17)
InitR(28,29,30,31,32,33,34,35,36,1,10,19,37,46,55,64,73,38,39,47,48)
InitR(29,28,30,31,32,33,34,35,36,2,11,20,38,47,56,65,74,37,39,46,48)
InitR(30,28,29,31,32,33,34,35,36,3,12,21,39,48,57,66,75,37,38,46,47)
InitR(31,28,29,30,32,33,34,35,36,4,13,22,40,49,58,67,76,41,42,50,51)
InitR(32,28,29,30,31,33,34,35,36,5,14,23,41,50,59,68,77,40,42,49,51)
InitR(33,28,29,30,31,32,34,35,36,6,15,24,42,51,60,69,78,40,41,49,50)
InitR(34,28,29,30,31,32,33,35,36,7,16,25,43,52,61,70,79,44,45,53,54)
InitR(35,28,29,30,31,32,33,34,36,8,17,26,44,53,62,71,80,43,45,52,54)
InitR(36,28,29,30,31,32,33,34,35,9,18,27,45,54,63,72,81,43,44,52,53)
InitR(37,38,39,40,41,42,43,44,45,1,10,19,28,46,55,64,73,29,30,47,48)
InitR(38,37,39,40,41,42,43,44,45,2,11,20,29,47,56,65,74,28,30,46,48)
InitR(39,37,38,40,41,42,43,44,45,3,12,21,30,48,57,66,75,28,29,46,47)
InitR(40,37,38,39,41,42,43,44,45,4,13,22,31,49,58,67,76,32,33,50,51)
InitR(41,37,38,39,40,42,43,44,45,5,14,23,32,50,59,68,77,31,33,49,51)
InitR(42,37,38,39,40,41,43,44,45,6,15,24,33,51,60,69,78,31,32,49,50)
InitR(43,37,38,39,40,41,42,44,45,7,16,25,34,52,61,70,79,35,36,53,54)
InitR(44,37,38,39,40,41,42,43,45,8,17,26,35,53,62,71,80,34,36,52,54)
InitR(45,37,38,39,40,41,42,43,44,9,18,27,36,54,63,72,81,34,35,52,53)
InitR(46,47,48,49,50,51,52,53,54,1,10,19,28,37,55,64,73,29,30,38,39)
InitR(47,46,48,49,50,51,52,53,54,2,11,20,29,38,56,65,74,28,30,37,39)
InitR(48,46,47,49,50,51,52,53,54,3,12,21,30,39,57,66,75,28,29,37,38)
InitR(49,46,47,48,50,51,52,53,54,4,13,22,31,40,58,67,76,32,33,41,42)
InitR(50,46,47,48,49,51,52,53,54,5,14,23,32,41,59,68,77,31,33,40,42)
InitR(51,46,47,48,49,50,52,53,54,6,15,24,33,42,60,69,78,31,32,40,41)
InitR(52,46,47,48,49,50,51,53,54,7,16,25,34,43,61,70,79,35,36,44,45)
InitR(53,46,47,48,49,50,51,52,54,8,17,26,35,44,62,71,80,34,36,43,45)
InitR(54,46,47,48,49,50,51,52,53,9,18,27,36,45,63,72,81,34,35,43,44)
InitR(55,56,57,58,59,60,61,62,63,1,10,19,28,37,46,64,73,65,66,74,75)
InitR(56,55,57,58,59,60,61,62,63,2,11,20,29,38,47,65,74,64,66,73,75)
InitR(57,55,56,58,59,60,61,62,63,3,12,21,30,39,48,66,75,64,65,73,74)
InitR(58,55,56,57,59,60,61,62,63,4,13,22,31,40,49,67,76,68,69,77,78)
InitR(59,55,56,57,58,60,61,62,63,5,14,23,32,41,50,68,77,67,69,76,78)
InitR(60,55,56,57,58,59,61,62,63,6,15,24,33,42,51,69,78,67,68,76,77)
InitR(61,55,56,57,58,59,60,62,63,7,16,25,34,43,52,70,79,71,72,80,81)
InitR(62,55,56,57,58,59,60,61,63,8,17,26,35,44,53,71,80,70,72,79,81)
InitR(63,55,56,57,58,59,60,61,62,9,18,27,36,45,54,72,81,70,71,79,80)
InitR(64,65,66,67,68,69,70,71,72,1,10,19,28,37,46,55,73,56,57,74,75)
InitR(65,64,66,67,68,69,70,71,72,2,11,20,29,38,47,56,74,55,57,73,75)
InitR(66,64,65,67,68,69,70,71,72,3,12,21,30,39,48,57,75,55,56,73,74)
InitR(67,64,65,66,68,69,70,71,72,4,13,22,31,40,49,58,76,59,60,77,78)
InitR(68,64,65,66,67,69,70,71,72,5,14,23,32,41,50,59,77,58,60,76,78)
InitR(69,64,65,66,67,68,70,71,72,6,15,24,33,42,51,60,78,58,59,76,77)
InitR(70,64,65,66,67,68,69,71,72,7,16,25,34,43,52,61,79,62,63,80,81)
InitR(71,64,65,66,67,68,69,70,72,8,17,26,35,44,53,62,80,61,63,79,81)
InitR(72,64,65,66,67,68,69,70,71,9,18,27,36,45,54,63,81,61,62,79,80)
InitR(73,74,75,76,77,78,79,80,81,1,10,19,28,37,46,55,64,56,57,65,66)
InitR(74,73,75,76,77,78,79,80,81,2,11,20,29,38,47,56,65,55,57,64,66)
InitR(75,73,74,76,77,78,79,80,81,3,12,21,30,39,48,57,66,55,56,64,65)
InitR(76,73,74,75,77,78,79,80,81,4,13,22,31,40,49,58,67,59,60,68,69)
InitR(77,73,74,75,76,78,79,80,81,5,14,23,32,41,50,59,68,58,60,67,69)
InitR(78,73,74,75,76,77,79,80,81,6,15,24,33,42,51,60,69,58,59,67,68)
InitR(79,73,74,75,76,77,78,80,81,7,16,25,34,43,52,61,70,62,63,71,72)
InitR(80,73,74,75,76,77,78,79,81,8,17,26,35,44,53,62,71,61,63,70,72)
InitR(81,73,74,75,76,77,78,79,80,9,18,27,36,45,54,63,72,61,62,70,71)
Back to top
View user's profile Send private message AIM Address
JBensimon



Joined: 16 Nov 2004
Posts: 130
Location: New York

PostPosted: Mon Oct 16, 2006 3:30 am    Post subject: Reply with quote

Smile Two week-ends, to be specific.

The piece of code you quoted (which pre-defines a specific 81x20 matrix) is a shortcut way of identifying the 20 "peers" of any Sudoku grid entry. Using the entries in this matrix allows the puzzle to be stored and manipulated as an 81-element vector rather than a 9x9 matrix, which significantly cuts down on index calculations and speeds up the identification of candidates for any empty cell. My original Sudoku solver was (literally) a two-line recursive APL program (anybody remember APL?), and I pre-calculated that matrix as a way of making that program fast -- I just ported it to AHK when I decided to try creating a GUI version. The solving algorithm is also ported from my original APL program (which is why it's only about 15 lines in AHK).

Jacques.
Back to top
View user's profile Send private message Visit poster's website
JBensimon



Joined: 16 Nov 2004
Posts: 130
Location: New York

PostPosted: Wed Nov 08, 2006 3:23 am    Post subject: Reply with quote

As promised, I've posted a finished (for now) version of the program and its code. See the following post in the "Scripts & Functions" forum:

http://www.autohotkey.com/forum/viewtopic.php?t=13995

Jacques.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group