当前位置: 首页>>代码示例>>PHP>>正文


PHP permute函数代码示例

本文整理汇总了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]);
    }
}
开发者ID:amira-s,项目名称:etna-projects,代码行数:7,代码来源:tri.php

示例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);
        }
    }
}
开发者ID:paperclipninja,项目名称:webdev,代码行数:11,代码来源:permute.php

示例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);
        }
    }
}
开发者ID:nickysemenza,项目名称:algorithms,代码行数:15,代码来源:string_permutations.php

示例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;
}
开发者ID:shangdawei,项目名称:HID-Card-Copy,代码行数:12,代码来源:permute.php

示例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.
        }
    }
}
开发者ID:eltonoliver,项目名称:Algorithms,代码行数:13,代码来源:string_permutations.php

示例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;
}
开发者ID:neeraj-webdev,项目名称:interview-quest,代码行数:14,代码来源:permutation.php

示例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);
        }
    }
}
开发者ID:sergchernata,项目名称:Advent-of-Code,代码行数:14,代码来源:21.php

示例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;
 }
开发者ID:aaron-em,项目名称:advent-of-code,代码行数:15,代码来源:13.php

示例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;
}
开发者ID:TagGerr,项目名称:advent-of-code,代码行数:16,代码来源:Day09.php

示例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);
        }
    }
}
开发者ID:johnjp15,项目名称:WEB_DEV,代码行数:17,代码来源:permutations.php

示例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;
}
开发者ID:altef,项目名称:AdventOfCode,代码行数:17,代码来源:Day13.php

示例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;
}
开发者ID:Ma-ve,项目名称:AdventOfCode2015,代码行数:18,代码来源:day13.php

示例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;
}
开发者ID:ricardclau,项目名称:tuenti-contest,代码行数:22,代码来源:test7.php

示例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);
            }
        }
    }
}
开发者ID:johnjp15,项目名称:WEB_DEV,代码行数:23,代码来源:permutations2_old.php

示例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);
开发者ID:sergchernata,项目名称:Advent-of-Code,代码行数:18,代码来源:17.php


注:本文中的permute函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。