Results 1 to 7 of 7
  1. #1
    Mirix is offline Member
    Join Date
    May 2010
    Location
    Alexandria, VA
    Posts
    14
    Rep Power
    0

    Default Algorithm help? :)

    I am trying to write an algorithm where my robot can shift piles of beepers on the first row over one column. (disregard the second row, it is only there to serve as reference.)
    example:


    Could anyone give me an idea of how this can be done please?
    I understand that I would have to count the number of beepers on each pile and somehow keep track of them to move them over?

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    What's the exact way of moving? Is that a pile can move one column at a time to any direction?

  3. #3
    Mirix is offline Member
    Join Date
    May 2010
    Location
    Alexandria, VA
    Posts
    14
    Rep Power
    0

    Default

    You are moving to the East :)
    So you are pushing each pile of beepers one tile to the right.

  4. #4
    Mirix is offline Member
    Join Date
    May 2010
    Location
    Alexandria, VA
    Posts
    14
    Rep Power
    0

    Default

    I have managed to achieve this task using 10 different variables (one for each row) since the grid is 10 by 10.
    The steps are:
    1. picks up and counts beepers in first column, assigns the number to variable "a"
    2. moves to the second column
    3. picks up and counts beepers in second column, assigns the number to variable "b"
    4. drops the "a" amount of beepers in the second column
    5. moves to the third column
    6. picks up and counts beepers in the third column, assigns the number to variable "c"
    7. drops the "b" amount of beepers in the third column.

    ...and so forth.
    This way seems pretty tedious though, since I had to assign 10 different variables for each of the columns.
    Are there any other ways? or are there any ways to reset each variable to zero so I can loop this instead of repeating the same steps over and over?

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  6. #6
    Mirix is offline Member
    Join Date
    May 2010
    Location
    Alexandria, VA
    Posts
    14
    Rep Power
    0

    Default

    The picture shows the "Before" and "After" stages of the program.
    Our main purpose is to push the "beepers" or those black dots with numbers (indicating how many of them are in a pile) on them, one tile to the right.
    As you can see, in the first figure, the first and second row of beepers are aligned.
    In the second figure, the robot have successfully moved the first row of beepers to the right (hence, the un-alignment). And returned to (1, 1)

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by Mirix View Post
    I have managed to achieve this task using 10 different variables (one for each row) since the grid is 10 by 10.
    The steps are:
    1. picks up and counts beepers in first column, assigns the number to variable "a"
    2. moves to the second column
    3. picks up and counts beepers in second column, assigns the number to variable "b"
    4. drops the "a" amount of beepers in the second column
    5. moves to the third column
    6. picks up and counts beepers in the third column, assigns the number to variable "c"
    7. drops the "b" amount of beepers in the third column.

    ...and so forth.
    This way seems pretty tedious though, since I had to assign 10 different variables for each of the columns.
    Are there any other ways? or are there any ways to reset each variable to zero so I can loop this instead of repeating the same steps over and over?
    As you said defining many variables is not a good idea. It assign you to do lots of work.

    Can't we something like this, keep the record of each piles as a coordinate value, in a map or something relevant collection. Then you've use the x,y coordinate again to access the info.

Similar Threads

  1. Need some help in an algorithm
    By ea09530 in forum New To Java
    Replies: 3
    Last Post: 04-04-2010, 01:13 PM
  2. Help with an Algorithm
    By Manfizy in forum New To Java
    Replies: 22
    Last Post: 07-03-2009, 07:16 AM
  3. O(log n) algorithm help !!!!!!
    By itseeker87 in forum New To Java
    Replies: 8
    Last Post: 09-09-2008, 05:12 PM
  4. Help with algorithm
    By susan in forum New To Java
    Replies: 1
    Last Post: 07-13-2007, 10:26 PM
  5. Help me with this algorithm
    By Marcus in forum Advanced Java
    Replies: 3
    Last Post: 07-02-2007, 01:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •