Algorithm HELP!!!

This is a discussion on Algorithm HELP!!! within the C Programming forums, part of the General Programming Boards category; Any more info on this code? I'm stuck on trying to understand what it's doing. First, I don't see an ...

  1. #31
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    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. #32
    Registered User
    Join Date
    Feb 2011
    Posts
    16
    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. #33
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,649
    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. #34
    Registered User
    Join Date
    Feb 2011
    Posts
    16
    Quote Originally Posted by rags_to_riches View Post
    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. #35
    Registered User
    Join Date
    Aug 2006
    Posts
    12
    Quote Originally Posted by alexdavid View Post
    Code:
    /* Code that isn't even C */
    There .. fixed.
    You don't even have a compiler, do you?

    LT

  6. #36
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,649
    Quote Originally Posted by alexdavid View Post
    Yes it is, i am desperate to have someone do this for me, is making me CRAAAZY
    There, fixed that for you.

  7. #37
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by alexdavid View Post
    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. #38
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Adak View Post
    (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?');
         Readln(Name);
         if Name = '' then
            Exit;
         Writeln('Your name is ',Name);
      end;
     
    begin
       GetName;
    end.

  9. #39
    Registered User
    Join Date
    Aug 2006
    Posts
    12
    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. #40
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    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. #41
    Registered User
    Join Date
    Feb 2011
    Posts
    16
    Quote Originally Posted by Adak View Post
    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. #42
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    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. #43
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    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.

    Then add the threading part.

    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.

    Your thoughts?

  14. #44
    Registered User
    Join Date
    Feb 2011
    Posts
    16
    Quote Originally Posted by Adak View Post
    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.

    Then add the threading part.

    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.

    Your thoughts?
    thank you i am working on it, i will tell you!! and that algorith they gave it to me just to see how the problem could be!!!

Page 3 of 3 FirstFirst 123
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Implement of a Fast Time Series Evaluation Algorithm
    By BiGreat in forum C Programming
    Replies: 7
    Last Post: 12-04-2007, 01:30 AM
  2. Replies: 4
    Last Post: 12-10-2006, 06:08 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21