Some slightly different answers besides "google it", that I've given students who haven't ever programmed before (they'd only seen examples on the board in class, for the most part) for this exact same problem:
First, programming isn't just using a programming language. The hardest thing is deciding what you want to say in the first place in a way that's specific enough for the computer to understand. In the sense of needing to be specific with what you say, computers are like a perverse cross of a recalcitrant 3-year-old and a pedantic professor of law.
So, the first program you should write should be in English (or Swedish, or whatever you speak).
For this problem, I'd start with the smallest instance (4x4, if I recall correctly), and do it by hand.
1234
1 q
2q
3 q
4 q
Write down your steps, something like this:
1. Put a queen at (1, 3).
2. Put a queen at (2, 1).
3. Put a queen at (3, 4).
4. Put a queen at (4, 2).
This only solves 4-queens, and only in one way, but it gives you a start, and you'll have to solve a couple of problems that you'd need to do anyway if you tried to do it all at once.
Now, translate these statements into a programming language. You'll need to be specific about where to put the queen, so refine it to something like this:
1. Put a queen on the board at (1, 3).
Now you're getting somewhere when it comes to translating this to a computer language. There's a board, a queen, and you do something to them. So, in terms of your program, you know have something like this:
1. Define what the board is.
2. Define what a queen is.
3. Define how you put a queen on the board.
4. Do that list I made before.
The board has to have rows and columns, so an array of arrays might be a good fit. A queen could simply be the string "queen". And then putting a queen on the board would just be setting a particular element in the array to "queen".
How do you pick a square?
- it can't be threatened by any other queen.
How do you tell if a square is threatened?
- No queens in the same row, coloumn, or on the diagonals.
How do you check the row, column, and diagonals?
...
Once it works for 4 squares, what about 5? 6? n?
Now, this isn't something to do *instead* of Google, in fact, having the answer right in front of you can be really helpful, since what you're doing isn't strictly trying to find the answer, but trying to find how to get to the answer.
Best of luck,
matt.
···
On Dec 7, 2005, at 17:02, BAT wrote:
I'm sorry if you felt like i'm trying to get the code from you! That
wasn't the thing i was asking for!! I use to do my homework myself. I
just wanted to know which is the best way to start solving the problem
as a person without knowledge in programming.
anyway, thanks for your quick replies