Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,673 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,177 people online right now. Registration is fast and FREE... Join Now!




Doubts with arrays

2 Pages V  1 2 >  
Reply to this topicStart new topic

Doubts with arrays

storm123
post 21 Aug, 2007 - 05:38 AM
Post #1


New D.I.C Head

*
Joined: 20 Aug, 2007
Posts: 22


My Contributions


Hi,
I'm trying to write a 4x4 sudoku source code with Visual Studio 6.0 and I've deciced to use arrays.
I've thought in
CODE

int puzzle[4][4]  

How to get the columns, rows and squares contain all 1,2,3,4?
I dunno if I can get that using loops, conditional sentences or whatever. I need some help.
Thank you.
User is offlineProfile CardPM

Go to the top of the page

Bench
post 21 Aug, 2007 - 06:28 AM
Post #2


D.I.C Addict

Group Icon
Joined: 20 Aug, 2007
Posts: 602



Thanked 10 times

Dream Kudos: 150

Expert In: C/C++

My Contributions


QUOTE(storm123 @ 21 Aug, 2007 - 02:38 PM) *

Hi,
I'm trying to write a 4x4 sudoku source code with Visual Studio 6.0 and I've deciced to use arrays.
I've thought in
CODE

int puzzle[4][4]  

How to get the columns, rows and squares contain all 1,2,3,4?
I dunno if I can get that using loops, conditional sentences or whatever. I need some help.
Thank you.
You need to be a little more specific -
What exactly do you want it to look like at the end? do you want the 1,2,3,4 in any particular order? perhaps in sequence throughout the array, similar to the schematic shown?
CODE
  1   2   3   4
  1   2   3   4
  1   2   3   4
  1   2   3   4


If you're looking for it to generate a full sudoku off the cuff, then you need to do some research on sudoku algorithms (Remember that there are a huge number of different possible combinations of sudoku's ..)

This post has been edited by Bench: 21 Aug, 2007 - 06:30 AM
User is offlineProfile CardPM

Go to the top of the page

Louisda16th
post 21 Aug, 2007 - 06:39 AM
Post #3


 

Group Icon
Joined: 3 Aug, 2006
Posts: 1,790



Thanked 1 times

Dream Kudos: 755
My Contributions


Firstly, welcome to </DIC> smile.gif
This is the wrong forum (you should have posted in the Visual Basic forum). Also please don't double post.
What exactly do you want to do with your array?
If you want to initialize it, you will require two loops.
Please explain your problem and show whatever code you have attempted.

This post has been edited by Louisda16th: 21 Aug, 2007 - 06:40 AM
User is offlineProfile CardPM

Go to the top of the page

Bench
post 21 Aug, 2007 - 06:52 AM
Post #4


D.I.C Addict

Group Icon
Joined: 20 Aug, 2007
Posts: 602



Thanked 10 times

Dream Kudos: 150

Expert In: C/C++

My Contributions


QUOTE(Louisda16th @ 21 Aug, 2007 - 03:39 PM) *

This is the wrong forum (you should have posted in the Visual Basic forum). Also please don't double post.
Ah, I was under the impression that the OP was using MSVC++ (Although a very outdated, pre-standard version)
User is offlineProfile CardPM

Go to the top of the page

William_Wilson
post 21 Aug, 2007 - 06:56 AM
Post #5


lost in compilation

Group Icon
Joined: 23 Dec, 2005
Posts: 3,970



Thanked 15 times

Dream Kudos: 3275

Expert In: Java, C, Javascript

My Contributions


do not double post, it is likely to get you less help rather than more.
please delete: http://www.dreamincode.net/forums/index.ph...c=32005&hl=
User is offlineProfile CardPM

Go to the top of the page

skyhawk133
post 21 Aug, 2007 - 07:01 AM
Post #6


Head DIC Head

Group Icon
Joined: 17 Mar, 2001
Posts: 14,846



Thanked 45 times

Dream Kudos: 1650

Expert In: Web Development

My Contributions


done.
User is offlineProfile CardPM

Go to the top of the page

Xing
post 21 Aug, 2007 - 07:47 AM
Post #7


D.I.C Addict

Group Icon
Joined: 22 Jul, 2006
Posts: 723



Thanked 2 times

Dream Kudos: 1575
My Contributions


QUOTE(storm123 @ 21 Aug, 2007 - 07:08 PM) *

Hi,
I'm trying to write a 4x4 sudoku source code with Visual Studio 6.0 and I've deciced to use arrays.
I've thought in
CODE

int puzzle[4][4]  

How to get the columns, rows and squares contain all 1,2,3,4?
I dunno if I can get that using loops, conditional sentences or whatever. I need some help.
Thank you.



QUOTE(Bench @ 21 Aug, 2007 - 08:22 PM) *

QUOTE(Louisda16th @ 21 Aug, 2007 - 03:39 PM) *

This is the wrong forum (you should have posted in the Visual Basic forum). Also please don't double post.
Ah, I was under the impression that the OP was using MSVC++ (Although a very outdated, pre-standard version)


Post only talks about Visual Studio 6.0. There's no mention about the language of use. Only OP can clear it.
User is offlineProfile CardPM

Go to the top of the page

Louisda16th
post 21 Aug, 2007 - 09:29 AM
Post #8


 

Group Icon
Joined: 3 Aug, 2006
Posts: 1,790



Thanked 1 times

Dream Kudos: 755
My Contributions


Mmm. Didn't see that properly tongue.gif. Should have seen the declaration. int puzzle would refer to C.
User is offlineProfile CardPM

Go to the top of the page

born2c0de
post 22 Aug, 2007 - 08:46 AM
Post #9


printf("I'm a %XR",195936478);

Group Icon
Joined: 26 Nov, 2004
Posts: 3,905



Thanked 34 times

Dream Kudos: 2800

Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions


QUOTE
Ah, I was under the impression that the OP was using MSVC++ (Although a very outdated, pre-standard version)

Its the same thing. VC++ 6.0 is a part of MS Visual Studio 6.0
User is offlineProfile CardPM

Go to the top of the page

storm123
post 23 Aug, 2007 - 02:31 AM
Post #10


New D.I.C Head

*
Joined: 20 Aug, 2007
Posts: 22


My Contributions


I want to generate a small 4x4 sudoku off the cuff using arrays I've tried to use that array:
CODE
int main ( ) {
    int puzzle[4][4] = {
        {  a,  b,  c , d },
        { d,  e,  f,  g },
        { h,  i,   j,  k },
        { l,  m,  n, o },
    };

(letters can be random numbers between 1 and 4)
I only want to know how to get files, rows and squares contain only once every number.
'I've couldn't write the code cuz it's imposible follow with it if I don't know how to do that.
I use C++
Thank you
User is offlineProfile CardPM

Go to the top of the page

dlkj
post 25 Aug, 2007 - 02:27 AM
Post #11


D.I.C Head

**
Joined: 11 Mar, 2002
Posts: 137

your syntax seems correct. If you replaced the a, b, c, d, etc with constant numbers I believe it will work.

However, since you're initializing the array, it has to be done with constants, not variables. If the a, b, c, d, etc are all variables, then you have little choice but to do this
CODE

puzzle[0][0] = a;
puzzle[0][1] = b;
// and so on
puzzle[3][2] = n;
puzzle[3][3] = o;


this would be done somewhere further down in your main function.

If you're asking for the algorithm to determine the values of the a to o variables, well here's how I would do it in a simple manner

fill in the puzzle row by row
have a 'set' of numbers 1 to 4. randomly pick numbers out of this set and fill in the first row. (if you've picked a number, it can no longer be selected for the same row).
repeat for each row. however, additional constraints apply.
- if any of the above rows have the same number in the same column, put the number back and randomly select again.
- if any in the same 2x2 square have the same number, put the number back and select again

Assuming that all sudoku puzzles have a solution I believe that the algorithm should work. you probably try to generate a couple of thousand solution to test the theory.

since we keep on putting back the numbers and reselect when we hit the constraint, this might be a wasteful algorithm as we have to try many times. However, it is simple. I haven't read up on the popular algo used so I'm sure there are optimizations available.
figuring out how to check the constraints correctly in a generic manner that can be easily extended to 9x9 grid might be challenging.
figuring out which numbers to 'hide' so that the puzzle solver can take a reasonable shot at it is also challenging.
User is offlineProfile CardPM

Go to the top of the page

storm123
post 3 Sep, 2007 - 07:06 AM
Post #12


New D.I.C Head

*
Joined: 20 Aug, 2007
Posts: 22


My Contributions


Ok thank you for the answer.
I have a question about what you have said.
How to make a set of numbers in order to pick them randomly one by one in C++.
Thank you smile.gif
User is offlineProfile CardPM

Go to the top of the page

2 Pages V  1 2 >
Reply to this topicStart new topic
Time is now: 11/23/08 06:18AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month