Ejemplo n.º 1
0
 /**
  * @param Pool $pool
  *
  * @return array|bool
  */
 private function shuffleTillMatch(Pool $pool)
 {
     $timeToStop = microtime(true) + self::SHUFFLE_TIME_LIMIT;
     $entries = $pool->getEntries()->getValues();
     while (microtime(true) < $timeToStop) {
         $set = $this->shuffleArray($entries);
         if ($this->checkValidMatch($entries, $set)) {
             $this->matchedExcludes = $set;
             return $set;
         }
     }
     return false;
 }
Ejemplo n.º 2
0
 /**
  * @param Pool $pool
  * @return array|bool
  */
 private function permutateTillMatch(Pool $pool)
 {
     $entries = $pool->getEntries()->getValues();
     $set = $this->shuffleArray($entries);
     $size = count($set) - 1;
     $perm = range(0, $size);
     do {
         $shuffled = array();
         foreach ($perm as $i) {
             $shuffled[] = $set[$i];
         }
         if ($this->checkValidMatch($entries, $shuffled)) {
             return $shuffled;
         }
     } while ($perm = $this->nextPermutation($perm, $size));
     return false;
 }