Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Okay, for those who just join in on this post, please read through all the comments to the question before considering the contents of this answer, as this will very likely fly over your head.</p> <p>Here is some pseudo code in PHP'ish style:</p> <pre><code>/* Array with profs (this is one dimensional here for the show, but I assume it will be multi-dimensional, filled with availability and what not; For the sake of this example, let me say that the multi-dimensional array contains the following keys: [id]{[avail_from],[avail_to],[last_ses],[name]}*/ $profs = array_fill(0, $prof_num, "assoc_ids"); // Array with time slots, let's say UNIX stamps of begin time $times = array_fill(0, $slot_num, "time"); // First, we need to loop through all the time slots foreach ($times as $slot) { // See when session ends $slot_end = $slot + $session_time; // Now, run through the profs to see who's available $avail_profs = array(); // Empty foreach ($profs as $prof_id =&gt; $data) { if (($data['avail_from'] &gt;= $slot) &amp;&amp; ($data['avail_to'] &gt;= $slot_end)) { $avail_prof[$prof_id] = $data['last_ses']; } } /* Reverse sort the array so that the highest numbers (profs who have been waiting the longest) will be up top */ arsort($avail_profs); $profs_session = array_slice($avail_profs, 0, 3); $profs_session_names = array(); // Empty // Reset the last_ses counters on those profs foreach ($profs_session as $prof_id =&gt; $last_ses) { $profs[$prof_id]['last_ses'] = 0; $profs_session_names[0] = $profs[$prof_id]['name']; } // Now, loop through all profs to add one to their waiting time foreach ($profs as $prof_id = &gt; $data) { $profs[$prof_id]['last_ses']++; } print(sprintf('The %s session will be held by: %s, $s, and %s&lt;br /&gt;', $slot, $profs_session_names[0], $profs_session_names[1], $profs_session_names[2]); unset ($profs_session, $profs_session_names, $avail_prof); } </code></pre> <p>That should print something like:</p> <pre><code>The 9:40am session will be held by: C. Hicks, A. Hole, and B.E.N. Dover </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload