Click here to Skip to main content
15,890,185 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# Messenger Pin
I Believe In GOD26-Aug-09 12:17
I Believe In GOD26-Aug-09 12:17 
GeneralRe: C# Messenger Pin
harold aptroot26-Aug-09 12:47
harold aptroot26-Aug-09 12:47 
AnswerRe: C# Messenger Pin
Patrick Eckler26-Aug-09 12:03
Patrick Eckler26-Aug-09 12:03 
GeneralRe: C# Messenger Pin
harold aptroot26-Aug-09 12:10
harold aptroot26-Aug-09 12:10 
AnswerRe: C# Messenger Pin
N a v a n e e t h26-Aug-09 16:02
N a v a n e e t h26-Aug-09 16:02 
GeneralRe: C# Messenger Pin
I Believe In GOD27-Aug-09 3:03
I Believe In GOD27-Aug-09 3:03 
QuestionProgrammatically import Access DB into SQL Express Pin
benford26-Aug-09 9:46
benford26-Aug-09 9:46 
QuestionSudoku problem [modified] Pin
GravityKoch26-Aug-09 9:45
GravityKoch26-Aug-09 9:45 
Hello guy´s

I´ve a problem with the implementation of Sudoku in c#....

i wrote 2 for-loops, one that tests the collums, one that tests the rows if the numbers 1-9 are unique in a row/col... The 2 Loops are working perfect, but only if i use ONE of them.. The 2 loops are not working together , I think it´s a Overflow...
I try to interlace the for-loops, but i´m with stupid.. I have to ask for help in this forum

here is a bit of code
using System;
using System.Collections.Generic;
using System.Text;

namespace sudoku
{
    class sudoku
    {
        private int[] values_right = new int[81];

        private int[] squareindex = new int[81] {0, 0, 0, 1, 1, 1, 2, 2, 2,
                                                 0, 0, 0, 1, 1, 1, 2, 2, 2,
                                                 0, 0, 0, 1, 1, 1, 2, 2, 2,
                                                 3, 3, 3, 4, 4, 4, 5, 5, 5,
                                                 3, 3, 3, 4, 4, 4, 5, 5, 5, 
                                                 3, 3, 3, 4, 4, 4, 5, 5, 5, 
                                                 6, 6, 6, 7, 7, 7, 8, 8, 8, 
                                                 6, 6, 6, 7, 7, 7, 8, 8, 8, 
                                                 6, 6, 6, 7, 7, 7, 8, 8, 8};

        private int[] posible_values = new int[9] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

        public sudoku()
        {
            this.generate();
        }

        public void generate()
        {
            /*
            int[] values = {8, 4, 6, 3, 5, 1, 7, 9, 2, 
                            5, 1, 3, 9, 2, 7, 4, 6, 8, 
                            7, 9, 2, 6, 8, 4, 1, 3, 5,
                            4, 3, 8, 5, 7, 9, 6, 2, 1, 
                            1, 7, 9, 2, 4, 6, 5, 8, 3, 
                            2, 6, 5, 8, 1, 3, 9, 7, 4, 
                            6, 8, 1, 7, 3, 5, 2, 4, 9, 
                            9, 2, 4, 1, 6, 8, 3, 5, 7, 
                            3, 5, 7, 4, 9, 2, 8, 1, 6};
            */


            Random rnd = new Random();
            int i;
           


            for (i = 0; i < 81; i++)
            {
                while (this.values_right[i] == 0)
                    this.values_right[i] = rnd.Next(1, 90) % 10;


                while (check_position(i) == 0)
                {
                    this.values_right[i] = (this.values_right[i] + 1) % 10;

                }
            }

        }

        public int[] get_values_right()
        {
            return values_right;
        }

        int check_position(int i)
        {
            if (this.values_right[i] == 0)
                return 0;

            Random rnd = new Random();
            int row = i - (i % 9);
            int col = i % 9;
            int position;

             for (position = row; position < row + 9; position++)
            {
                if (position == i)
                    continue;

                if (this.values_right[position] == this.values_right[i])
                    return 0;
            }

           /*for (position = col; position < 80; position += 9)
            {
                if (position == i)
                    continue;

                if (this.values_right[position] == this.values_right[i])
                    return 0;
            }*/


            return 1;
        }
    }
}




Thanks for help, members of coding...
I´m sure, its only a LITTLE 1-MINUTE problem 4 you..

Thank again..^^

modified on Thursday, August 27, 2009 2:25 AM

AnswerRe: Sudoku problem Pin
EliottA26-Aug-09 11:21
EliottA26-Aug-09 11:21 
AnswerRe: Sudoku problem Pin
Henry Minute26-Aug-09 14:49
Henry Minute26-Aug-09 14:49 
GeneralRe: Sudoku problem Pin
GravityKoch26-Aug-09 20:26
GravityKoch26-Aug-09 20:26 
QuestionLoading status bar for data in other form !! Pin
rocky81126-Aug-09 9:29
rocky81126-Aug-09 9:29 
AnswerRe: Loading status bar for data in other form !! Pin
I Believe In GOD26-Aug-09 9:58
I Believe In GOD26-Aug-09 9:58 
AnswerRe: Loading status bar for data in other form !! Pin
DaveyM6926-Aug-09 10:04
professionalDaveyM6926-Aug-09 10:04 
QuestionProblem wrting to custom config element Pin
CTaylor8926-Aug-09 9:25
CTaylor8926-Aug-09 9:25 
QuestionDrag and Drop Pin
JimLaVine26-Aug-09 9:07
JimLaVine26-Aug-09 9:07 
AnswerRe: Drag and Drop Pin
kKamel26-Aug-09 11:18
kKamel26-Aug-09 11:18 
GeneralRe: Drag and Drop Pin
JimLaVine26-Aug-09 11:20
JimLaVine26-Aug-09 11:20 
GeneralRe: Drag and Drop Pin
kKamel26-Aug-09 11:22
kKamel26-Aug-09 11:22 
AnswerRe: Drag and Drop Pin
Kevin Marois26-Aug-09 11:51
professionalKevin Marois26-Aug-09 11:51 
QuestionMouse Scheme in windows Pin
caiena26-Aug-09 7:11
caiena26-Aug-09 7:11 
AnswerRe: Mouse Scheme in windows Pin
I Believe In GOD26-Aug-09 9:56
I Believe In GOD26-Aug-09 9:56 
QuestionProgress bar [loading progress bar for background data load ] Pin
smoothcriminal26-Aug-09 6:29
smoothcriminal26-Aug-09 6:29 
AnswerRe: Progress bar [loading progress bar for background data load ] Pin
Henry Minute26-Aug-09 7:12
Henry Minute26-Aug-09 7:12 
AnswerRe: Progress bar [loading progress bar for background data load ] Pin
DaveyM6926-Aug-09 7:23
professionalDaveyM6926-Aug-09 7:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.