advice for Sudoku-solver

This is a discussion on advice for Sudoku-solver within the C++ Programming forums, part of the General Programming Boards category; I am trying to make a Sudoku-solver, so far I have made the class 'board' and a way to enter ...

  1. #1
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312

    advice for Sudoku-solver

    I am trying to make a Sudoku-solver, so far I have made the class 'board' and a way to enter which field you want to fill with a number (the beginning numbers). How should I store the numbers? With arrays?
    Operating Systems:
    - Ubuntu 9.04
    - XP

    Compiler: gcc

  2. #2
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    Use [3][3][3] array for storing numbers, In order to solve it think for yourself, do you know the rules?
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  3. #3
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312
    yes, with counting the total value of the numbers in rows, columns and squares.

    Edit: [3][3][3] is wrong, because you have 27 fields in that array and you need: 9 * 9 fields. [9][9] seems to be the right solution for me.
    Last edited by Ideswa; 07-31-2006 at 04:58 AM.
    Operating Systems:
    - Ubuntu 9.04
    - XP

    Compiler: gcc

  4. #4
    The larch
    Join Date
    May 2006
    Posts
    3,573
    I wrote a (lousy) logical solver recently. I used a Cell class, and a Sudoku (board) class which had 3 copies of a [81] array of Cells: one sorted by rows, one by column and one by regions. Each cell object also had 2 pointers (or array indices) to the corresponding Cells in the other 2 arrays, so that by modifying a cell in respect to a row, I could modify the corresponding cells in column and region. Having three copies of the board may not be too efficient, but it sure made scanning each row, column and region a lot easier (and the program works reasonably fast).

    On second thought it would have been even better to use one [3][81] array for the three copies of the board (I basically had a lot of copied-n-pasted code), but I was almost finished when it occurred to me.

  5. #5
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    Do it the VERY long way! the one that would have ~9^40 possibilities!!!

    I've been thinking about making one for ages, but I haven't gotten around to it. I'll prob do it next year in college when I should be doing something different.

    However, I'd recommend that you attempt to make the solver function the same way you attempt to solve the puzzle yourself. If you can solve a puzzle, do one again, but write down the methodology you employ to solve it, and the pseudocode a rough function. There should be a number of functions you could use in your program. As I said, try some puzzles, write down how you solve them, and then try to write the program.

    EDIT - maybe he meant a [9][9][9] array ...

  6. #6
    Registered User
    Join Date
    Jul 2005
    Posts
    14
    Here's an article about it: http://www.osix.net/modules/article/?id=792.

  7. #7
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312
    Thanks for the tips!
    Operating Systems:
    - Ubuntu 9.04
    - XP

    Compiler: gcc

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Advice on C Programming with MSVC++ 2008
    By IT_Guy in forum Windows Programming
    Replies: 1
    Last Post: 03-06-2009, 03:23 AM
  2. Resume advice
    By Zughiaq in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-15-2005, 02:16 PM
  3. girl friend advice (prob. the wrong place)
    By B0bDole in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 10-22-2004, 06:38 PM
  4. need hardware advice....
    By forgottenPWord in forum Tech Board
    Replies: 5
    Last Post: 03-23-2003, 08:12 AM
  5. Newbie: Seek advice
    By gogo in forum C++ Programming
    Replies: 4
    Last Post: 11-06-2001, 09:04 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21