Passing in a grid to a function with bikes and person at locations
[ \'c\' , \'_\' ,\'A\' ,\'_\', \'_\' , \'_\']
[ \'_\' , \'_\' ,\'a\' ,\'_\', \'_\' , \'_\']
[
I will outline the steps for you
Find the location of Bikes and Person and store them in an Array.
person = [[0,2],[4,0],[4,5],[5,3]], bikes = [[0,0],[1,2],[2,4],[4,1]];
Define a Class ( lets call it Distance
) having following variables:
person_id: use person index (0, 1, 2, ...)
bike_id: use bike index (0, 1, 2, ...)
dist: distance between this person and bike
Create an array of Distance
objects for each pair of person and bike. So for the above example you will have object values
[(0, 0, 2), (0, 1, 1), ...(3, 3, 3)]
dist
Create two Boolean arrays person_used having same number of elements as number of persons and bike_used having same number of elements as number of bikes(both initialized as false).
person_used = [false, false, false, false], bike_used = [false, false, false, false]
Iterate through the array. If for the current Distance
object person_used[person_id] == false && bike_used[bike_id] == false
assign this person to this bike and set both person_used[person_id] and bike_used[bike_id] to true
. If either is false
you can ignore it.