Ruby newcomer

Hi all!

I'm totally new to ruby (and don't have much experience with
programming at all) and need to implement a program (for school) which
shows a solution for the nQueensProblem. It should be able to show the
solutions even if the "chessboard" is bigger than 8x8!
Can anyone give me some ideas how to get this program done quickly?

best regards Bernhard

What part are you having trouble with? Dive right in and then just post questions here as you have them. If you back yourself into a corner, we'll get you out. :wink:

James Edward Gray II

···

On Dec 7, 2005, at 10:27 AM, BAT wrote:

Can anyone give me some ideas how to get this program done quickly?

BAT wrote:

Hi all!

I'm totally new to ruby (and don't have much experience with
programming at all) and need to implement a program (for school) which
shows a solution for the nQueensProblem. It should be able to show the
solutions even if the "chessboard" is bigger than 8x8!
Can anyone give me some ideas how to get this program done quickly?

best regards Bernhard

Firstly you gain ten points for being honest and telling us that you are asking us to do your school work.

However you loose all these points and more for not using that indispensable programming tool...

GOOGLE

Try "n queens problem" and just remember than unless your teacher is a complete idiot they will have done this too.

Asking a mailing list to do your homework for you is poor form. I
suggest you google "n queens problem" and you'll find many good
resources.

When you have a Ruby-specific question, we'll be glad to help.

regards,
Ed

···

On Thu, Dec 08, 2005 at 01:27:35AM +0900, BAT wrote:

Can anyone give me some ideas how to get this program done quickly?

http://www.math.utah.edu/~alfeld/queens/queens\.

···

On 12/7/05, BAT <b.trapp@gmx.at> wrote:

Hi all!

I'm totally new to ruby (and don't have much experience with
programming at all) and need to implement a program (for school) which
shows a solution for the nQueensProblem. It should be able to show the
solutions even if the "chessboard" is bigger than 8x8!
Can anyone give me some ideas how to get this program done quickly?

best regards Bernhard

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

Have a look at the Ruby Quiz site.

Chess Variants Quiz. Might give you some ideas.

http://rubyquiz.com/quiz35.html
http://rubyquiz.com/quiz36.html

As others have said, use Google or whatever materials your teacher has
provided to get the basic algorithm for solving the problem. Then code
that algorithm in Ruby. If you look at some of the quizzes and
solutions on rubyquiz.com, you will quickly see that even simple
problems can be solved in many different ways in Ruby. It is a very
flexible language, which is why so many of us enjoy it so much.

Ryan

···

On 12/7/05, BAT <b.trapp@gmx.at> 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

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

Well, it won't help you with your homework, but if you're looking for
an introduction to Ruby aimed at those with no previous experience, I
wrote this:

  http://pine.fm/LearnToProgram/

Let me know if you get stuck or anything.

:slight_smile:

Chris