Thread: Help with this impossible code [Weave's Island]

  1. #1
    Registered User
    Join Date
    Jul 2016
    Posts
    1

    Help with this impossible code [Weave's Island]

    Hello everyone, I am currently studying computer engineering and about to finish my semester, anyway, my C programming teacher is terrible, barely speaks english and doesn't know how to give an understandable class and suddenly gives us this impossible assignment that I have no idea how to write since we barely saw the topics we are supposed to use. I would be forever grateful if someone helps me with this, thank you. Here's the assignment (I attached the final code):

    For your second assignment this semester, you are required to write
    a program for a logic game called "Weaver's Island".
    The object of the game is transport "cargo" (Monkeys, Coconuts, and
    Alligators) from a land port to an island.
    In order to "transport" the cargo, you will need a "ship" (a character array)
    that allows you to "transport" only 1 item at a time.

    However, the game has the following rules:
    1. Only 1 type of cargo can be transported at a time.

    2. The Monkeys cannot be left alone with the Alligators
    because the Alligators will eat the Monkeys.

    3. The Monkeys cannot be left alone with the Coconuts, because
    the Monkeys will eat the Coconuts.
    In order to complete this assignment, you will be required
    to complete the code for the following functions that make use of
    characters strings.
    Recall:
    A string is a character array that is terminated with the null byte '\0'.
    Also, you may make use of any of the <string.h> library
    functions you wish (for example, strlen( )).
    Code:
    void loadCargo(char ship[ ], char land[ ], char type); 
    void transportCargo(char ship[ ], char destination[ ], int dir); 
    
    void loadCargo(char ship[ ], char land[ ], char type); 
    
    This function copies all of the characters that match the character
    'type' from the 'land' string into the 'ship' array.
    Once all of the characters have been copied into the ship array,
    you must terminate the array with the null byte in order to make
    it a proper string.
    Also, after each character is copied from the 'land' string it MUST
    be changed to lowercase (i.e. 'C' to 'c', 'M' to 'm', etc).
    An uppercase character can be changed to lowercase by adding 32
    to the uppercase character.

    void transportCargo(char ship[ ], char destination[ ], int dir);
    This function can be used to copy characters from the 'ship' string
    into the 'destination' string (either the 'land' or the 'island').
    If the integer value 'dir' is 1, this function copies all of the
    characters in the 'ship' string to the end of the 'destination' string
    (from ship to island).

    If the integer value 'dir' is 0, then this function copies each
    character in the 'ship' string that matches its lowercase equivalent
    in the 'destination' string (replacing the lowercase equivalent in the
    'destination' string) (from ship back to land).

    NOTE: If copying characters from the ship to the island, don't forget
    to add the null byte at the end into the destination array.


    OUTPUT:
    -----------------
    The following program (once you have coded and called the functions
    properly):

    Code:
    #include <stdio.h> 
    #include <string.h> 
    
    void loadCargo(char ship[ ], char land[ ], char type); 
    void transportCargo(char ship[ ], char destination[ ], int dir); 
    
    void printRegion(char region[ ], int dir); 
    
    int main( ) { 
    char land[121] = "CCCCCCCCAAAAAAAAAAAAAAAAAAAAAMMMMM"; 
    char island[121] = ""; 
    char ship[121] = ""; 
    int i; 
    
    /* 
    YOUR CODE HERE... 
    YOUR CODE HERE...
    
    • /
    printRegion(land, 1); printRegion(island, 0); return 0; } void loadCargo(char ship[ ], char land[ ], char type) { /* YOUR CODE HERE... */ } void transportCargo(char ship[ ], char destination[ ], int dir) { /* YOUR CODE HERE... */ } void printRegion(char region[ ], int dir) { int i; printf("%s: ", dir == 1 ? "LAND" : "ISLAND"); for(i=0; region[i] != '\0'; i++) { printf("%c", region[i]); } printf("\n"); } would display: LAND: ccccccccaaaaaaaaaaaaaaaaaaaaammmmm ISLAND: mmmmmAAAAAAAAAAAAAAAAAAAAACCCCCCCCMMMMM
    NOTE: the lowercase letters in the 'land' string indicate that
    they have all been moved, and the uppercase letters indicate
    that they have been added.


    SUBMITTING YOUR ASSIGNMENT:
    ---------------------------
    Test your program on the C platforms that your instructor has
    specified. For submission purposes, your program must work
    on DevC++ version 5.11. For detailed submission requirements
    follow your instructor's assignment submission guidelines.
    Attached Images Attached Images Help with this impossible code [Weave's Island]-sin-t-tulo-png 
    Last edited by datrainbow; 07-26-2016 at 12:02 AM.

  2. #2
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    Is the program supposed to figure out the logic by trial and error, or are you allowed to determine which two cargo types can be left alone (which would mean the remaining type is transported first)?

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    Ignore the code, do you know how to solve the problem?

    One approach is to randomly transport the denizens until you find a solution.

    Another approach is to try all possible combinations of transporting the cargo until you find one which doesn't result in something being eaten by something else.

    Or you could think about the problem at an abstract level to work out how to solve the problem, if all you have is a pencil and paper. It's generally more efficient than writing reams of code and burning minutes of machine time.
    Spoiler - select all text to see it

    1. Take monkeys
    2. Return empty
    3. Take coconuts
    4. Return with monkeys
    5. Take alligators
    6. Return empty
    7. Take monkeys


    > my C programming teacher is terrible
    Are you only complaining now, or did you raise your concerns at the start of the course?
    Because we get an awful lot of posts which begin with "my teacher sucks...".
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 15
    Last Post: 02-18-2013, 05:08 PM
  2. Impossible ! (H.E.L.P)
    By Bat Ako in forum C Programming
    Replies: 2
    Last Post: 10-14-2012, 01:06 AM
  3. Desert Island Top Five
    By Govtcheez in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 10-12-2004, 05:36 PM
  4. Impossible
    By krappykoder in forum C++ Programming
    Replies: 17
    Last Post: 11-01-2002, 03:26 PM
  5. Island In The Sun
    By gnu-ehacks in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 11-27-2001, 09:06 PM

Tags for this Thread