# Thread: Algorithm HELP!!!

1. Any more info on this code?

I'm stuck on trying to understand what it's doing. First, I don't see an array for the board[8][8] (or so), and the 2 to 16 arrays are weird. It says "diagonals", but diagonals on a chessboard are just 8 squares long, so I'm thinking it's really two diagonals (which would be 15 squares)??

Then, in main(), it sets all the array elements to TRUE, but mentions that TRUE indicates the element has a queen??

The "coup de grace" is the array with negative and positive indeces, of course!

My questions:

How much can you change these arrays and logic, and be OK?
This IS the put 8 queens on the chessboard without attacking any of the other queens, RIGHT?

sometimes i need someone to tick me off and then i will react
I believe we've all been there, at some time or other.

2. hello, thank you for answering, i can change it as much as i could, the thing is to solve the 8 queen problem using a master/slave programming, which means that the master will start to fill a board with a queen starting by the diagonal, then this board must to be delivered to the slave, and then that slave have to do its own job of filling up the 7 queens into that board, for that they request me to use fork() which creates child processes with the same code but an only ID!! and then the parent have to wait until the slaves finish their job and report it at the end

3. Are you actually under the impression that the pseudocode you posted -- which is directly from your assignment, based on the deleted post at DevShed I found in the Google cache (post 5) is C?

4. Originally Posted by rags_to_riches
Are you actually under the impression that the pseudocode you posted -- which is directly from your assignment, based on the deleted post at DevShed I found in the Google cache (post 5) is C?
Yes it is, i am desperate to complete this, is making me CRAAAZY

5. Originally Posted by alexdavid
Code:
`/* Code that isn't even C */`
There .. fixed.
You don't even have a compiler, do you?

LT

6. Originally Posted by alexdavid
Yes it is, i am desperate to have someone do this for me, is making me CRAAAZY
There, fixed that for you.

7. Originally Posted by alexdavid
Yes it is, i am desperate to complete this, is making me CRAAAZY
That code is NOT C, and it says that right in the original post that it's from: Dr. Wirth's book on Algorithms and Data Structures.

Understand:

1) C can't use negative indeces in an array.

2) Dr. Wirth is the father of Pascal, and an innovator in Modula 2 (iirc), and other languages.

He was a top notch programmer, author, and researcher in computer languages. I'm not, and I can't wrap my head around the algorithm, fully.

(Doubly difficult since I don't know Pascal, which is what this program is written in apparently).

The 8 queen's problem isn't that tough, and you can do your fork and such to it, as required. But don't use this program, as anything more than a loose template.

Is the 8 queens problem what has you stuck, or is it the child processes, etc.?

8. Originally Posted by Adak
(Doubly difficult since I don't know Pascal, which is what this program is written in apparently).
I'm thinking it was some kind of hybridized pseudocode....

This is pascal...
Code:
```program Procedures;

procedure GetName;
var
Name: String;
begin
Writeln('What is your name?');
if Name = '' then
Exit;
Writeln('Your name is ',Name);
end;

begin
GetName;
end.```

9. I have read (some of) Wirth's books, he likes to use simplified versions of IBM's PL/1 and (in his later books) Oberon, which he created. Both look similar to Pascal at a glance.

Offtopic: His books on compiler building are actually pretty good. The last version of his book on compiler building can be found on the web as a free download. (If you fancy that sort of thing).

LT

10. Good info.

Might have to look up Wirth's book although I've never messed with compiler building before. I suspect it will create a large wooshing sound as it zips over my head, but still ...

So now you have no trouble believing I know nothing (almost), about Pascal, anyway!

11. Originally Posted by Adak
Good info.

Might have to look up Wirth's book although I've never messed with compiler building before. I suspect it will create a large wooshing sound as it zips over my head, but still ...

So now you have no trouble believing I know nothing (almost), about Pascal, anyway!
Hello, well do you have an email address? then i could send you all the stuff and you'll see what do i need, my problem is that i don't know how to put a process to work in soemthing and then put the parent to wait for the return from his child or childs!!! :S

12. Let's keep the discussion here, for the simple reason that buds here on the forum, know a HELL of a lot more about programming than I do. Also**

Have you considered using fork() and then wait() for the parent?

Just looking in Google, I found post after post on various forums (including our own C++ forum, involving fork().

** last time I did that, the boy friend got jealous, and took a knife to my avatar. That's why I don't have an avatar, to this very day <tear> --- RIP avatar!

13. Here's what I suggest:

1) The thread part of this is a small amount of code, and how it should be implemented (as far as an algorithm), is explained in your post:
Place the first queen, and then find the rest (if possible) with the child thread.

I'm no expert on threads and processes, but that doesn't seem like a big big deal, because it's just a few lines of code, and many examples and discussions of it, on the net.

My point being, that you should concentrate on getting the rest of the program coded up and working, first.

2) With #1 in mind, you have to know that this code you posted can't work in C, as it is. It's impossible. If you can code up an 8 queens program yourself, do that. If not, see what you can find, that IS C code, and you have some chance of understanding.

Sometimes you can take a program in another language, and "translate it" into C pretty easily. But not the posted program. It's deeply integrated into the language (PL/1, Oberon, or whatever it is), and can't be "translated".

Also, it's from a book by a world famous author - you certainly can't turn it in and say "here's my program". They might even expel you for such an obvious act of plagiarism.

14. Originally Posted by Adak
Here's what I suggest:

1) The thread part of this is a small amount of code, and how it should be implemented (as far as an algorithm), is explained in your post:
Place the first queen, and then find the rest (if possible) with the child thread.

I'm no expert on threads and processes, but that doesn't seem like a big big deal, because it's just a few lines of code, and many examples and discussions of it, on the net.

My point being, that you should concentrate on getting the rest of the program coded up and working, first.