Hiding random integers in an array

Aug 23, 2011 at 9:35pm
Hi guys!
I am not new here, but this is my first post.
Actually i have a lot of questions, beginner questions i think.
I was thinking about an array which has some of its values hidden.
Is there a command which can do this?
Also, i want to ask smth else about multidimensional arrays.
If i print one on the screen, how can i make its numbers
change places?
swap(array[3][2], [6][4], [1][5])
This is what i learned from your tutorial, correct me if i am wrong.
Also, i would be interested to know how can i randomly swap numbers
from each row and each coloumn.
Finally, how can i make a sudoku game?
I have all the code in Java, but don't get it all how to do in c++.
Pls help me!
Last edited on Aug 23, 2011 at 9:48pm
Aug 23, 2011 at 9:53pm
If i print one on the screen, how can i make its numbers
change places?
swap(array[3][2], [6][4], [1][5])


Can you please clarify?

I think if you have all the code in Java, converting it into C++ shouldn't be that complication.

Head over to the tutorial section and read up. There is priceless information there that can help you with the semeantics/syntax.

In short, to get started, look at the code below. I have written some comments.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream> // Used to do simple output/input to the screen
#include <math.> // You might need this for Sudoku solver

using namespace std; // Namespace where functions to output to screen reside

int main()
{
	int i;

	cout << "Hello, enter number"; // Use cout to output
	cin >> i; // Get the number from user input
	cout << "Your number is: " << i; // Output number
	
	cin.get(); // Pause

	return 0;
}
Aug 23, 2011 at 10:05pm
I am sorry!
I have all the code of sudoku in java!
Not the one i have written, that is meant to be in c++
Can you pls tell me if that is right? or wrong?
How should i write it?
Also, i know c++ man, i can show u a game i have written in 350 row codes, but i lack
a lot in arrays and some commands like swap or pivot.
I want to learn how to make a sudoku generator!
I have read all the array tutorial documentation, but it doesn't say
anything about swapping any integers with each other in the array
Last edited on Aug 23, 2011 at 10:10pm
Aug 23, 2011 at 10:13pm
Aug 23, 2011 at 10:41pm
Not Sudoku solver. That is when u have generated it.
I want to create the sudoku, meaning sudoku generator.
Also, if u know any advanced tutorials about the arrays
swaps or pivots, pls send me any link.
I have searched a lot of sudoku generators,
but there seems none has made a SIMPLE one.
Aug 24, 2011 at 3:12am
Scroll down to the section labeled "Sudoku Generation Algorithm"

http://davidbau.com/archives/2006/09/04/sudoku_generator.html

To sum it up, it pretty much says that your need to create a solve first. Once you do, you will backtrack. Or randomly select a list of blocks to display and hide the rest.
Aug 24, 2011 at 10:57am
A user there says this:

"I know a better way to generator:

1. get a valid one like:
1 2 3 4 5 6 7 8 9
4 5 6 7 8 9 1 2 3
7 8 9 1 2 3 4 5 6
2 3 4 5 6 7 8 9 1
5 6 7 8 9 1 2 3 4
8 9 1 2 3 4 5 6 7
3 4 5 6 7 8 9 1 2
6 7 8 9 1 2 3 4 5
9 1 2 3 4 5 6 7 8

2. then randomly switch two lines(row) in a group or switch two big groups.

3. randomly switch all positions for two numbers, like switch all 1 and 2
Actually you can do the step 3 before step 1.

Now you have a valid solution, you just need to get rid of number from it to create a sudoku."

How can i get rid of numbers randomly?
Last edited on Aug 24, 2011 at 10:57am
Topic archived. No new replies allowed.