List all combinations of option strings while following order of supplied array and rules of specific options - php -


i working on project company sells multitude of valves vast array of variations , need build site map links every valve data current navigation not use conventional links codes built via user interacting many options on page. have been able generate until options begin tricky because of vast array of combinations of these options there , rules follow.

i attempting build every option string combinations rules can find below.

given array of option codes (at end of post) must generate list of possible combinations must follow order presented , follow rules given row_mod. example when option_code of o in combinations option_code of on , op not allowed in combination.

the row_mod info needs followed when building these strings "nawithop##" refers option not allowed it.

some of possible combinations need come out of script be:

  1. otkz
  2. otk
  3. ot
  4. otosz
  5. otos
  6. o
  7. ol
  8. olkz
  9. olk

i know isn't close exhaustive list of how many possible can't figure out how generate possible combinations.


array (     [0] => array         (             [option_code] => o             [row_mod] => allowall nawithopon nawithopop         )      [1] => array         (             [option_code] => on             [row_mod] => allowall nawithopo nawithopop         )      [2] => array         (             [option_code] => op             [row_mod] => allowall nawithopo nawithopon         )      [3] => array         (             [option_code] => t             [row_mod] => allowall nawithopl         )      [4] => array         (             [option_code] => l             [row_mod] => allowall nawithopt nawithcoilx         )      [5] => array         (             [option_code] => k             [row_mod] => allow2 allow3 allow3p nawithopos         )      [6] => array         (             [option_code] => os             [row_mod] => allow2 allow3 allow3p nawithopk         )      [7] => array         (             [option_code] => z             [row_mod] => allowall nawithpreb         )  ) 

basically must start on first option code , iterate down list starting first given option 'o' go next option 'on' , check whether valid , if add current combination. , on , forth building allowed combinations , storing them array.

user interface example: created jsfiddle interactive in way options work together. found here

i'm not sure approach should taking have tried using recursive algorithms no avail.

you have 8 different options, appear usable either 0 or 1 times. "not used" makes nine. have

  • 9 possibilities first option,
  • 8 possibilities second (since first cannot reused),
  • 7 possibilities third (since first 2 cannot reused)
  • ...

your basic number of options then, not counting rules option compatibility, 9!, or 362880 combinations.

you cycle through possible combinations, , write function test whether combination valid, given rules each type. list items function returns true, , reject others. might bit slow, it'll work.

to generate these combinations, visualise sequence of options 9-digit number in base 9 (i.e. have 9 things , can each take 1 of 9 values, subject limitations note below). think right in saying 99 (38742048910) different combinations, if there no rule disallow option being used twice.

thus, loop through these numbers in base 9, reject numbers have duplicate digits, , of ones through, convert options string, , reject don't pass per-options rule function. list of items left full set of permitted combinations.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -