Thread: sudoku in c

  1. #1
    Registered User
    Join Date
    May 2013
    Posts
    2

    Question sudoku in c

    can you help me please, i get a task about sudoku game 3x3 use 1 2 and 3 number, and the quantity of a row or a column is 6,
    please help me yaaa, thank you

  2. #2
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    You could use the brute force approach and just try all 6^3 = 216 possible permutations. Each row can only be one of 6 possible permutations:

    Code:
    {1,2,3}, {1,3,2}, {2,1,3}, {2,3,1}, {3,1,2}, {3,2,1}

  3. #3
    Registered User
    Join Date
    May 2012
    Posts
    505
    Quote Originally Posted by rcgldr View Post
    You could use the brute force approach and just try all 6^3 = 216 possible permutations. Each row can only be one of 6 possible permutations:

    Code:
    {1,2,3}, {1,3,2}, {2,1,3}, {2,3,1}, {3,1,2}, {3,2,1}
    Yes, this links in with another thread where we were discussing big O notation.
    The O(N!) method is probably going to be the best approach when N is 3. But it won't scale up to real Sudoku, where N is 9.
    I'm the author of MiniBasic: How to write a script interpreter and Basic Algorithms
    Visit my website for lots of associated C programming resources.
    https://github.com/MalcolmMcLean


  4. #4
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    Quote Originally Posted by Malcolm McLean View Post
    Yes, this links in with another thread where we were discussing big O notation.
    The O(N!) method is probably going to be the best approach when N is 3. But it won't scale up to real Sudoku, where N is 9.
    Apparently there are brute force solvers for real Sudoku, since the minimum number of filled in squares reduces the number of permutations, to one that a typical PC can solve reasonably quickly. Wiki article:

    Sudoku solving algorithms - Wikipedia, the free encyclopedia

  5. #5
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    A simple solution is backtracking:
    Keep filling the board with random numbers, as long as the rules are respected.
    If the rules are broken ( no number fits ) then go back to the previous cell and try a different available number.
    This algorithm is ( almost? ) always implemented using recursion.
    Last edited by GReaper; 05-22-2013 at 11:25 AM.
    Devoted my life to programming...

  6. #6
    Registered User
    Join Date
    May 2013
    Posts
    2
    yes, i know the possible permutations, but i don't know the code in c

  7. #7
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Code doesn't just appear, it is developed. Give a start and when you get stuck, post your attempt and you'll get more help. Nobody is going to hand you code (in case you missed it, you should read the homework policy).

  8. #8
    Lurker
    Join Date
    Dec 2004
    Posts
    296
    I guess that this is an assignment for some sort of beginners programming course?

    My advice is to sit down with pen and paper and try to construct a solution to this. You can't write a program unless you understand the problem at hand and how to solve it. Construct a pen and paper algorithm for solving this.

    If it is for a programming course, then you actually should be able to complete this assignment. If you can't then you either have a bad instructor or you have been slacking in class.

    Feel free to come back with specific questions when you start to develop a solution. We are happy to help you when you have some code to show.

    Good luck.

  9. #9
    Registered User ledow's Avatar
    Join Date
    Dec 2011
    Posts
    435
    Imagine the following being posted on a novellist's forum:

    "can you help me please, i want to write a book about a political thriller using three characters and some plot twists
    please help me yaaa, thank you"

    "yes, i know it would involve writing in proper grammar, but i don't know the how to write in English".

    Just how far do you think you'd get? And would you honestly expect someone to just write the book for you and give it to you?

    - Compiler warnings are like "Bridge Out Ahead" warnings. DON'T just ignore them.
    - A compiler error is something SO stupid that the compiler genuinely can't carry on with its job. A compiler warning is the compiler saying "Well, that's bloody stupid but if you WANT to ignore me..." and carrying on.
    - The best debugging tool in the world is a bunch of printf()'s for everything important around the bits you think might be wrong.

  10. #10
    Lurker
    Join Date
    Dec 2004
    Posts
    296
    Quote Originally Posted by ledow View Post
    Imagine the following being posted on a novellist's forum:

    "can you help me please, i want to write a book about a political thriller using three characters and some plot twists
    please help me yaaa, thank you"

    "yes, i know it would involve writing in proper grammar, but i don't know the how to write in English".

    Just how far do you think you'd get? And would you honestly expect someone to just write the book for you and give it to you?
    He can always pay somebody to get it done I guess. I'd be happy to do it for $200/h and I charge by started hour. ;-)

  11. #11
    Registered User
    Join Date
    Jan 2013
    Posts
    24
    You should look around on youtube, It was done by a professor at an austrailian college. I think it was divided up over 2 one hour videos. Goodluck with your search.

    char [9];

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sudoku in c
    By Alyaa in forum C Programming
    Replies: 5
    Last Post: 06-14-2012, 06:55 PM
  2. Sudoku
    By code_lover in forum C Programming
    Replies: 9
    Last Post: 09-16-2011, 11:19 AM
  3. Like Sudoku, but not.
    By quzah in forum Game Programming
    Replies: 4
    Last Post: 08-27-2011, 05:33 AM
  4. sudoku
    By ElemenT.usha in forum C++ Programming
    Replies: 22
    Last Post: 02-14-2011, 10:46 PM
  5. Sudoku
    By mrusnak in forum C Programming
    Replies: 10
    Last Post: 03-20-2009, 06:31 AM

Tags for this Thread