Results 1 to 7 of 7
Thread: Algorithm help? :)
 05232010, 04:49 PM #1Member
 Join Date
 May 2010
 Location
 Alexandria, VA
 Posts
 14
 Rep Power
 0
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?
 05232010, 05:37 PM #2
 Join Date
 Jul 2007
 Location
 Colombo, Sri Lanka
 Posts
 11,370
 Blog Entries
 1
 Rep Power
 26
What's the exact way of moving? Is that a pile can move one column at a time to any direction?
 05232010, 05:45 PM #3Member
 Join Date
 May 2010
 Location
 Alexandria, VA
 Posts
 14
 Rep Power
 0
You are moving to the East :)
So you are pushing each pile of beepers one tile to the right.
 05232010, 05:52 PM #4Member
 Join Date
 May 2010
 Location
 Alexandria, VA
 Posts
 14
 Rep Power
 0
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?
 05232010, 05:53 PM #5
 Join Date
 Jul 2007
 Location
 Colombo, Sri Lanka
 Posts
 11,370
 Blog Entries
 1
 Rep Power
 26
But in both figures you are in the same place, only the direction of it changed..
 05232010, 06:04 PM #6Member
 Join Date
 May 2010
 Location
 Alexandria, VA
 Posts
 14
 Rep Power
 0
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 unalignment). And returned to (1, 1)
 05242010, 02:08 AM #7
 Join Date
 Jul 2007
 Location
 Colombo, Sri Lanka
 Posts
 11,370
 Blog Entries
 1
 Rep Power
 26
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

Need some help in an algorithm
By ea09530 in forum New To JavaReplies: 3Last Post: 04042010, 01:13 PM 
Help with an Algorithm
By Manfizy in forum New To JavaReplies: 22Last Post: 07032009, 07:16 AM 
O(log n) algorithm help !!!!!!
By itseeker87 in forum New To JavaReplies: 8Last Post: 09092008, 05:12 PM 
Help with algorithm
By susan in forum New To JavaReplies: 1Last Post: 07132007, 10:26 PM 
Help me with this algorithm
By Marcus in forum Advanced JavaReplies: 3Last Post: 07022007, 01:30 PM
Bookmarks