本文整理汇总了PHP中permute函数的典型用法代码示例。如果您正苦于以下问题:PHP permute函数的具体用法?PHP permute怎么用?PHP permute使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了permute函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sort_array
function sort_array(&$array)
{
for ($i = 0; $i < sizeof($array); $i++) {
$min = return_indice_min($array, $i);
permute($array[$i], $array[$min]);
}
}
示例2: permute
function permute($prefix, $str, $array)
{
$n = strlen($str);
if ($n == 0) {
$array[$prefix] = 1;
} else {
for ($i = 0; $i < $n; $i++) {
permute($prefix . $str[$i], substr($str, 0, $i) . substr($str, $i + 1, $n), $array);
}
}
}
示例3: permute
/**
* Returns the Permutations of a String
*/
function permute($in, $startPos, $endPos)
{
if (strlen($in) == 1 || $startPos == $endPos) {
print $in . "\n";
return $in;
} else {
for ($a = $startPos; $a < $endPos; $a++) {
$in = swap($in, $startPos, $a);
permute($in, $startPos + 1, $endPos);
}
}
}
示例4: generate
function generate($key)
{
echo " input key: ";
dumpkey($key);
echo " permuted key: ";
$permuted = permute($key);
dumpkey($permuted);
echo " CRC'ed key: ";
$crc = crc($permuted);
dumpkey($crc);
return $crc;
}
示例5: permute
function permute($str, $i, $n)
{
if ($i == $n) {
print "{$str}\n";
} else {
for ($j = $i; $j < $n; $j++) {
swap($str, $i, $j);
permute($str, $i + 1, $n);
swap($str, $i, $j);
// backtrack.
}
}
}
示例6: permute
function permute($arg)
{
$array = is_string($arg) ? str_split($arg) : $arg;
if (1 === count($array)) {
return $array;
}
$result = array();
foreach ($array as $key => $item) {
foreach (permute(array_diff_key($array, array($key => $item))) as $p) {
$result[] = $item . $p;
}
}
return $result;
}
示例7: permute
function permute($items, $perms = array())
{
if (empty($items)) {
var_dump($perms);
} else {
for ($i = count($items) - 1; $i >= 0; --$i) {
$newitems = $items;
$newperms = $perms;
list($foo) = array_splice($newitems, $i, 1);
array_unshift($newperms, $foo);
permute($newitems, $newperms);
}
}
}
示例8: score
public function score($input)
{
$high_score = 0;
$edges = $this->get_edges($input);
$names = array_keys($edges);
$permuted_names = permute($names);
$high_score = 0;
foreach ($permuted_names as $seating) {
$seating_score = $this->score_seating($seating, $edges);
if ($seating_score > $high_score) {
$high_score = $seating_score;
}
}
return $high_score;
}
示例9: permute
function permute($list)
{
if (count($list) == 1) {
return array($list);
}
$permutations = array();
for ($l = 0; $l < count($list); $l++) {
$copy = $list;
$head = array_splice($copy, $l, 1);
$remaining = permute($copy);
foreach ($remaining as $tail) {
$permutations[] = array_merge($head, $tail);
}
}
return $permutations;
}
示例10: permute
function permute($str, $i, $n, &$arr)
{
//, &$arr) {
if (!is_array($arr)) {
$arr = array();
}
if ($i == $n) {
$arr[] = $str;
// print "$str\n";
} else {
for ($j = $i; $j < $n; $j++) {
swap($str, $i, $j);
permute($str, $i + 1, $n, $arr);
swap($str, $i, $j);
}
}
}
示例11: permute
function permute($list, $sofar = array())
{
global $combos;
if (count($list) == 0) {
$combos[] = $sofar;
return;
}
$output = array();
foreach ($list as $i => $l) {
$a = $list;
$b = $sofar;
$b[] = $l;
array_splice($a, $i, 1);
permute($a, $b);
}
return $output;
}
示例12: returnHappiness
function returnHappiness($input)
{
$table = processInput($input);
$results = [];
$combinations = permute(array_keys($table));
foreach ($combinations as $c) {
$happiness = 0;
for ($i = 0; $i < strlen($c); $i++) {
$personA = $c[$i];
$personB = $i === strlen($c) - 1 ? $c[0] : $c[$i + 1];
$happiness = happiness($happiness, $table[$personA][$personB]);
$happiness = happiness($happiness, $table[$personB][$personA]);
}
// echo $c . ': ' . $happiness . '<br>';
$results[] = $happiness;
}
return $results;
}
示例13: permute
function permute($str)
{
/* If we only have a single character, return it */
if (strlen($str) < 2) {
return array($str);
}
/* Initialize the return value */
$permutations = array();
/* Copy the string except for the first character */
$tail = substr($str, 1);
/* Loop through the permutations of the substring created above */
foreach (permute($tail) as $permutation) {
$length = strlen($permutation);
/* Loop through the permutation and insert the first character of the original
string between the two parts and store it in the result array */
for ($i = 0; $i <= $length; $i++) {
$permutations[] = substr($permutation, 0, $i) . $str[0] . substr($permutation, $i);
}
}
/* Return the result */
return $permutations;
}
示例14: permute
function permute($str, $i, $n, &$arr)
{
//, &$arr) {
if (!is_array($arr)) {
$arr = array();
}
if ($i == $n) {
$arr[] = $str;
// print "$str\n";
} else {
for ($j = $i; $j < $n; $j++) {
// if($str{$i} == $str{$j}) {
// // continue;
// echo "<br>i=" . $i . ", j=" . $j . "; charI = " . $str{$i} . ", charJ = " . $str{$j};
// }
if ($str[$i] != $str[$j] && $i === $j) {
swap($str, $i, $j);
permute($str, $i + 1, $n, $arr);
swap($str, $i, $j);
}
}
}
}
示例15: array
<?php
$input = "43\n3\n4\n10\n21\n44\n4\n6\n47\n41\n34\n17\n17\n44\n36\n31\n46\n9\n27\n38";
$perms = array();
$containers = arsort(explode("\n", $input));
function permute($items, $perms = array())
{
for ($i = 0; $i < count($items); $i++) {
$perm = array();
$max = 150;
$total = 0;
while ($total <= $max) {
# code...
}
}
}
$perms = permute($containers);
var_dump($perms);