Jump to content

Booking system woes


liamloveslearning

Recommended Posts

Hi there

 

Got a problem needs a solution, basically a booking system has been built (by me) and works great except for the checking availablity

 

Basically they can do drives in a car (in any order) so I need to try all possible combinations.

one idea I had was to use an array holding the availability for each slot so that it looks like

 

slotArray=array("ABC","AC","C","A","BC","AB","ABC" ...etc)

 

looking for drives A and B

 

so check if slotArray[1] contains A and Slot Array 2 contains b or vice versa

 

what i need to do is work out all the possible orders of a string ABCDE

(there will be 120 of them) so I can systematically check the order

anyone have a function that will do this?

 

Link to comment
Share on other sites

adapted from http://docstore.mik.ua/orelly/webprog/pcook/ch04_26.htm

 

function pc_permute($items, $perms = array( )) {
    if (empty($items)) { 
        print join(' ', $perms) . "\n";
    }  else {
        for ($i = count($items) - 1; $i >= 0; --$i) {
             $newitems = $items;
             $newperms = $perms;
             list($foo) = array_splice($newitems, $i, 1);
             array_unshift($newperms, $foo);
             pc_permute($newitems, $newperms);
         }
    }
}

$vals = array('A','B','C','D','E');

$res = pc_permute($vals);

print_r($res);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.