I’m trying to do the following, and can’t figure out how exactly do It without crashing or infinite looping:
I have to create a queue in which I have to distribute different tasks a different number of times each, alternatively with this kind of info:
-
Task X: [NextOne,LastOne]
- Task 1: [30,32]
- Task 2: [76,81]
- Task 3: [2,2]
- Task 4: [5,8]
Meaning that “Task X” will be made “LastOne – NextOne” times, and if both are equal, it won’t be enqueued, and they enter the queue in X order.
With this example, the queue should look like:
FIRST
Task1[30]
Task2[76]
Task4[5]
Task1[31]
Task2[77]
Task4[6]
Task1[32]
Task2[78]
Task4[7]
Task2[79]
Task4[8]
Task2[80]
Task2[81]
LAST
It’s not a language issue, it’s more of an algorithm issue I have here. Using PHP I’ve made the following:
$tasks = array(
'Task1' => array(30,32),
'Task2' => array(76,81),
'Task3' => array(2,2),
'Task4' => array(5,8)
);
$aux = array();
$i=0;
foreach($tasks as $s=>$n) {
$aux[$i]['task'] = $s;
$aux[$i]['times'] = $n[1]-$n[0];
$aux[$i]['first'] = $n[0];
$i++;
}
But as you imagine this actually does nothing, just change the shape of the information. I’m really stuck here I don’t know why, this actually shouldn’t be hard to figure out. I’d appreciate any help.
In python (I may be misinterpreting your “it’s not a language issue” comment – forgive me):
Sorry it’s not in php – it’s not my forte, but perhaps this’ll help? Output: