Skip to content

Instantly share code, notes, and snippets.

@vicegd
Created February 18, 2016 09:44
assignTasksToPlumbersBESTWAY()
/**
* Assigns tasks to the less busy plumber
* @param plumbers To save the tasks that any of the plumbers are going to perform
* @param tasks Final order in which the different tasks are going to be done
*/
public void assignTasksToPlumbersBESTWAY(int[][] plumbers, int[] tasks) {
int nPlumber = 0; //Index of the current plumber
for (int i = 0; i < tasks.length; i++) { //Each of the tasks
plumbers[nPlumber][i] = tasks[i]; //The current plumber performs the task
log.trace("\tPlumber: " + nPlumber + " is going to handled tasks of time: " + tasks[i]);
nPlumber++; //We go to the next plumber
if (nPlumber == plumbers.length) //If it is the last plumber, we start again
nPlumber = 0; //Again, first plumber
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment