Sudoku Programmers Forum Index

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log inLog in          Games  Calendar

Log in to check your private messagesLog in to check your private messages   

Bit Based Sudoku Solver (BB_Sudoku) V0.5
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9  Next
 
Post new topic   Reply to topic    Sudoku Programmers Forum Index -> Programming sudoku
View previous topic :: View next topic  
Author Message
Adak

Joined: 27 Feb 2008
Posts: 87
:

Items
PostPosted: Sun Nov 23, 2008 2:30 pm    Post subject: Reply with quote

I got an error message: Zero size reply

If you can put it up on Media Fire, OK. I can't go to lots of websites though. I get too many viruses that way.
Back to top
View user's profile Send private message
zhouyundong

Joined: 22 Nov 2008
Posts: 43
:

Items
PostPosted: Sun Nov 23, 2008 3:31 pm    Post subject: Reply with quote

hi,briturner,can you try this
000000000456789120789123450214365890065897210097214360031642970042978530000000000

what I got is :
Bit Based Sudoku Solver v0.2, by Brian Turner

000000000456789120789123450214365890065897210097214360031642970042978530000000000
000000000456789120789123450214365890065897210097214360031642970042978530000000000 - No Solution
---------------------
i got 123456789456789123789123456214365897365897214897214365531642978642978531978531642 and green led(means only one answer)
with my douzhi sodoku,win32 application
---------------------
another question:when you solve top 50000,do you give the result ,the result is "no answer, one answer, more answers"? It means when you get one solution,do you try to find if another solution is exist? Thank you.
I am now trace your source,very good source and very horner behaivor to upload source.
Back to top
View user's profile Send private message Send e-mail
zhouyundong

Joined: 22 Nov 2008
Posts: 43
:

Items
PostPosted: Sun Nov 23, 2008 4:47 pm    Post subject: Reply with quote

{ b = G[PIdx].Grid[Group[i][j]];
t2 = t2 | (t1 & b);
t1 = t1 | b;
if (B2V[b]) t3 = t3 | b;
}

t3 = ~(t2 | t3) & 0x01FF;
I know t1 means in 9 grids(3 kind of groups),111111111 is must.
t3 == true means this grid is single,such as 000010000
Back to top
View user's profile Send private message Send e-mail
briturner

Joined: 14 Oct 2008
Posts: 75
:

Items
PostPosted: Mon Nov 24, 2008 1:59 am    Post subject: Reply with quote

zhouyundong, in that code, t1 is the possibilities that have only been seen at least once, t2 is the possibilities that were seen more than one time. t3 is the numbers that are already known (This has been removed in newer versions).

A hidden single is then something that was seen one time, but not more than once, and is not already known


JasonLion, can I use the 500,000 puzzles you provided as another timing sample in my comparisons? I will not use it without your permission, but it would add a good point for people interested in generators.

I think i will do a generator next, already have some ideas of what I want to do. Basic idea I have is to place random numbers until I have a unique solution, then remove the givens one at a time to see if it was needed. I also plan on maintaining the partial solutions as I go along so I do not have to start from scratch with each new given added.

I have been reading other threads as well, and appreciate that my ideas are helping other people with their programs. There really is nothing new or revolutionary in what I am doing (unlike DLX which is a very elegant solutions that can be used in much more situations then my solver). I figured many others use similar ideas, since there are really only so many ways to write the solvers. I personally used the guide by Ruud as a basis of my program. I also appreciate people like JasonLion and zerothbase that have helped tweak parts of my algorithms.

brit
Back to top
View user's profile Send private message
JasonLion

Joined: 16 Nov 2008
Posts: 62
:
Location: Silver Spring, MD

Items
PostPosted: Mon Nov 24, 2008 1:06 pm    Post subject: Reply with quote

briturner wrote:
JasonLion, can I use the 500,000 puzzles you provided as another timing sample in my comparisons?


Sure! That was what I was hoping you would do.
Back to top
View user's profile Send private message
briturner

Joined: 14 Oct 2008
Posts: 75
:

Items
PostPosted: Tue Nov 25, 2008 3:53 am    Post subject: Reply with quote

ok JasonLion, I have updated the timing in the last post in the timing thread http://www.setbb.com/sudoku/viewtopic.php?p=10559&mforum=sudoku#10559

brit
Back to top
View user's profile Send private message
zhouyundong

Joined: 22 Nov 2008
Posts: 43
:

Items
PostPosted: Tue Nov 25, 2008 11:05 am    Post subject: Reply with quote

hi, briturner,
another question:when you solve top 50000,do you give the result ,the result is "no answer, one answer, more answers"? It means when you get one solution,do you try to find if another solution is exist? Thank you very much
and I think to generater, more than several ways can get.
what I do is: based on the given board by user, the result has 2 kinds:one is no answer or more answers,and another is only one answer.
if no answer or more answers,then random create board[0,1,2,3,4,5,6,7,8],then random create board[16,48,64,...128],top row and left column, but except board[the third row,the first column(32)],then get answer,here I have gotton random board[144].then random swap(1,2,3,4,5,6,7,8,9) for 20 times. then create random series[i], and one by one get rid of the board[series[i]],keep the result is only one answer
I can get 10000 games in 20000s
430021000000370000705000000060098004008000036000002008500009100000000070040000503
100004000000030608000700540006070080000309000098005000507100000809000000020000060
006000405320000000000307006010000700008050020000900040000003010500009000470000800
if only one answer,then create random series, and get rid of the board[series],keep the result is only one answer
for example:
when user give
006000405320000000000307006010000758008050020000900043000003010500009000470000800
run "Question",computer get
006000405320000000000307006010000700008050020000900040000003010500009000470000800

if the "QUESTION BOARD" has more than 24 numbers in it,then do Question again itself,until <= 24.


Last edited by zhouyundong on Tue Nov 25, 2008 11:24 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
zhouyundong

Joined: 22 Nov 2008
Posts: 43
:

Items
PostPosted: Tue Nov 25, 2008 11:12 am    Post subject: Reply with quote

Code:
void handleQuestion()
{
   int oldFlagAnswer;
   rightStatus = 3;
   getFlagAnswer();
   oldFlagAnswer = flagAnswer;
   mixupNumbers();
   moveBoard('b', 'a'); // board to answerBoard
   underQuestion = true;
   do
   {
      moveBoard('a', 'b'); // answerBoard to board
      getQuestion();
      getCountQuestion();
   } while(countQuestion > 24);

   moveBoard('b', 'r'); // board to rightBoard
   flagAnswer = oldFlagAnswer;
   underQuestion = false;
   underThinking = false;
}
void mixupNumbers1()
{
   int i;
   int index;
   int randStack[9];
   int pRandStack;
   // the first row
   for(i=0; i<9; i++)
   {
      randStack[i] = i+1;
   }
   pRandStack = 9;
   for(i=0; i<137; i++)
   {
      board[i] = 0;
   }
   while(pRandStack != 0)
   {
      index = rand() % pRandStack;
      board[9-pRandStack] = randStack[index];
      randStack[index] = randStack[--pRandStack];
   }
   // the first column
   board[16] = board[rand() % 6 + 3];
   for(i=0; i<8; i++)
   {
      randStack[i] = board[i+1];
   }
   for(i=2; i<8; i++)
   {
      if(randStack[i] == board[16])
      {
         randStack[i] = randStack[7];
         break;
      }
   }
   randStack[rand() % 5 + 2] = randStack[6];
   pRandStack = 6;
   while(pRandStack != 0)
   {
      index = rand() % pRandStack;
      board[(pRandStack+2)<<4] = randStack[index];
      randStack[index] = randStack[--pRandStack];
   }
}

void mixupNumbers2()
{
   int swapNumber1, swapNumber2;
   flagAnswer = 0;
   initialGame();
   getAnswer();
   for(int i=0; i<20; i++)
   {
      swapNumber1 = rand() % 9 + 1;
      swapNumber2 = rand() % 9 + 1;
      for(int j=0; j<137; j++)
      {
         if(answerBoard[j] == swapNumber1)
         {
            answerBoard[j] = swapNumber2;
         }
         else if(answerBoard[j] == swapNumber2)
         {
            answerBoard[j] = swapNumber1;
         }
      }
   }
   moveBoard('a', 'b'); // answerBoard to board
}
Back to top
View user's profile Send private message Send e-mail
zhouyundong

Joined: 22 Nov 2008
Posts: 43
:

Items
PostPosted: Tue Nov 25, 2008 11:18 am    Post subject: Reply with quote

Code:
void getQuestion()
{
   int i;
   int randStack[81];
   int pRandStack = 0;
   int indexDrop[81];
   int pIndexDrop = 0;
   int point;
   for(i=0; i<137; i++)
   {
      if(plusTbl[i] != 0 && board[i] != 0)
      {
         randStack[pRandStack++] = i;
      }
   }
   while(pRandStack != 0)
   {
      point = rand() % pRandStack;
      indexDrop[pIndexDrop++] = randStack[point];
      randStack[point] = randStack[--pRandStack];
   }
   // now we get indexDrop[pIndexDrop] and pIndexDrop
   for(i=0; i<pIndexDrop; i++)
   {
      moveBoard('b', 'k'); // board to bakBoard
      board[indexDrop[i]] = 0;
      initialGame();
      getAnswer();
      if(flagAnswer == 1)
      {
         bakBoard[indexDrop[i]] = 0;
      }
      moveBoard('k', 'b'); // bakBoard to board
   }
}
extern int board[144];
extern bool fix[144]; // 0: unfixed, 1: fixed
extern bool oldFix[144]; // just for show 0: unfixed, 1: fixed
extern int index;
extern int list[144*16]; // 4bits, 4bits, 4bits: xpos, ypos, value
extern int stack[10000];
extern int pStack;
extern int moveStack[2000];
extern int pMoveStack;
extern int flagAnswer; // 0: noanswer, 1: only one, 2: more than one
extern int bakBoard[144]; // reserve board for getting question
extern bool underQuestion; // under getting the question
extern int answerBoard[144]; // save the answer
extern int leftBoard[144]; // save the left board
extern int rightBoard[144]; // save the right board
extern int rightStatus; // status of the right board
extern bool dropable[144]; // can be dropped in condition of keeping flagAnswer is 1
extern int countQuestion; // the count of numbers of the question
extern bool underThinking; // computer is working to get answer or to get question
extern HANDLE runThread;

If the bothersome code bother you,forgive me please Smile
Back to top
View user's profile Send private message Send e-mail
briturner

Joined: 14 Oct 2008
Posts: 75
:

Items
PostPosted: Tue Nov 25, 2008 12:53 pm    Post subject: Reply with quote

greetings zhouyundong,

my program is currently a solver only, though I have started building a generator into it for the next version (not yet available to the public).

programwise, use a -s2 to check for uniqueness, -s+ for multiple results. in the code, when you call solver, you provide 3 parameters, the first telling if you stop at the first solution, 2nd, or try for all solutions. The first solution found is returned in the same buffer the puzzle is sent in.

My plan for a generator is similar, but will be integrated into the solver. Once a puzzle with a unique solution is found, I plan on running it through the solver with each given removed to minimize the puzzle.

I guess I am not sure exactly what you are asking.

brit
Back to top
View user's profile Send private message
zhouyundong

Joined: 22 Nov 2008
Posts: 43
:

Items
PostPosted: Tue Nov 25, 2008 1:12 pm    Post subject: Reply with quote

greetings briturner,
what user concern about is a question has one answer,no answer or more answer,if there are more answers,I think they have no interest to see every answer. even they have no interest to see the second answer.

So you may try to set a flag, tell solver to stop when solver has two solutions(not all solutions), and give user the first solution,and the same time give a message: more answers Very Happy

Can I use your public code into my software and sign "Kernel Written by Briturner" at the top bar of window?
Back to top
View user's profile Send private message Send e-mail
briturner

Joined: 14 Oct 2008
Posts: 75
:

Items
PostPosted: Tue Nov 25, 2008 1:51 pm    Post subject: Reply with quote

greetings zhouyundong,

I understand. as of the last version I released a few days ago, the Solver function does this.

When you call solver, you pass in if you want to stop at 1 solution, 2, or find all solutions. Only the first solution is passed back, even if more are found.

here are examples:

PuzCnt = Solver(1, ... // stops after 1 solution found. returns either 0 (no solution) or 1 (solution found)

PuzCnt = Solver(2, ... // Stops after 2 solutions, returns 0 (no solution), 1 (unique solution), or 2 (multiple solutions)


My code is posted so people can get their own ideas and build on my ideas, but please give me credit. If people want to use it for commercial profit, then we should discuss it.

I have not really published code, any one have a good idea of what license I should attach to this?

brit
Back to top
View user's profile Send private message
zhouyundong

Joined: 22 Nov 2008
Posts: 43
:

Items
PostPosted: Tue Nov 25, 2008 5:05 pm    Post subject: Reply with quote

About testing, not in allusion to any solver.

I think, speed test give result(0,1,2) and the first solution(result and solution do not display) is good than give the first solution only.
Embarassed
Back to top
View user's profile Send private message Send e-mail
zerothbase

Joined: 02 Nov 2008
Posts: 17
:

Items
PostPosted: Tue Nov 25, 2008 11:19 pm    Post subject: Reply with quote

Quote:
The majority of these puzzles are invalid in one way or another, typically having multiple solutions.

Quote:
I show 763 with one solution, 12,786 with more than one solution, and 486,451 with no solutions.


I'm not sure how 2.5% constitutes "typical".

Quote:
Optimizing for a set like this one is important for a checker used in puzzle generation.


Alternatively you can start from a random solved board and always choose subsets. Usually you can find a random subset with a unique solution of 30ish values (on a 3x3) fairly quickly and then reduce down to a minimum by removing values and checking for 1 or 2+ solutions. This way, you will never hit an unsolvable board - only 1 or 2+ solutions. Additionally, try hill-climbing (add one or two and then remove others) to get out of local-minima.

--zerothbase
Back to top
View user's profile Send private message
JasonLion

Joined: 16 Nov 2008
Posts: 62
:
Location: Silver Spring, MD

Items
PostPosted: Tue Nov 25, 2008 11:27 pm    Post subject: Reply with quote

zerothbase wrote:
I'm not sure how 2.5% constitutes "typical".


You are right, I mis-wrote.

You bring up a good point about the other style of puzzle generation. Adding clues until there is just one solution tends to produce puzzles with no solutions. I would expect that removing clues so long as there is still only one solution tends to result in puzzles with multiple solutions.

Both data sets are interesting and both are different from the other collections more commonly available. Would it be possible for you to post a collection of internal trial puzzles from a removing clues style solver?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Sudoku Programmers Forum Index -> Programming sudoku All times are GMT
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9  Next
Page 3 of 9

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Sudoku Programmers topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group

Igloo Theme Version 1.0 :: Created By: Andrew Charron