• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP permute函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中permute函数的典型用法代码示例。如果您正苦于以下问题:PHP permute函数的具体用法?PHP permute怎么用?PHP permute使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了permute函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: parse_bbc


//.........这里部分代码省略.........
            } elseif ($next_c != ']') {
                continue;
            }
            // Check allowed tree?
            if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) {
                continue;
            } elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) {
                continue;
            } elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) {
                continue;
            }
            $pos1 = $pos + 1 + strlen($possible['tag']) + 1;
            // Quotes can have alternate styling, we do this php-side due to all the permutations of quotes.
            if ($possible['tag'] == 'quote') {
                // Start with standard
                $quote_alt = false;
                foreach ($open_tags as $open_quote) {
                    // Every parent quote this quote has flips the styling
                    if ($open_quote['tag'] == 'quote') {
                        $quote_alt = !$quote_alt;
                    }
                }
                // Add a class to the quote to style alternating blockquotes
                $possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">'));
            }
            // This is long, but it makes things much easier and cleaner.
            if (!empty($possible['parameters'])) {
                $preg = array();
                foreach ($possible['parameters'] as $p => $info) {
                    $preg[] = '(\\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . ')' . (empty($info['optional']) ? '' : '?');
                }
                // Okay, this may look ugly and it is, but it's not going to happen much and it is the best way of allowing any order of parameters but still parsing them right.
                $match = false;
                $orders = permute($preg);
                foreach ($orders as $p) {
                    if (preg_match('~^' . implode('', $p) . '\\]~i', substr($message, $pos1 - 1), $matches) != 0) {
                        $match = true;
                        break;
                    }
                }
                // Didn't match our parameter list, try the next possible.
                if (!$match) {
                    continue;
                }
                $params = array();
                for ($i = 1, $n = count($matches); $i < $n; $i += 2) {
                    $key = strtok(ltrim($matches[$i]), '=');
                    if (isset($possible['parameters'][$key]['value'])) {
                        $params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
                    } elseif (isset($possible['parameters'][$key]['validate'])) {
                        $params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
                    } else {
                        $params['{' . $key . '}'] = $matches[$i + 1];
                    }
                    // Just to make sure: replace any $ or { so they can't interpolate wrongly.
                    $params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '&#036;', '{' => '&#123;'));
                }
                foreach ($possible['parameters'] as $p => $info) {
                    if (!isset($params['{' . $p . '}'])) {
                        $params['{' . $p . '}'] = '';
                    }
                }
                $tag = $possible;
                // Put the parameters into the string.
                if (isset($tag['before'])) {
                    $tag['before'] = strtr($tag['before'], $params);
开发者ID:AhoyLemon,项目名称:ballpit,代码行数:67,代码来源:Subs.backup.2.php


示例17: swap

 * 
 * 
 */
function swap(&$a, &$b)
{
    $temp = $a;
    $a = $b;
    $b = $temp;
}
function permute_swap($str, $i, $n)
{
    if ($i == $n - 1) {
        foreach ($str as $c) {
            echo $c;
        }
        echo "\n";
    } else {
        for ($j = $i; $j < $n; $j++) {
            // Backtracking
            swap($str[$i], $str[$j]);
            permute_swap($str, $i + 1, $n);
            swap($str[$i], $str[$j]);
        }
    }
}
function permute($str)
{
    permute_swap($str, 0, count($str));
}
permute(str_split($argv[1]));
开发者ID:ajaybhatia,项目名称:php-scripts,代码行数:30,代码来源:permutations.php


示例18: permute

function permute($list)
{
    $result = array();
    $inner = function ($items, $perms = array()) use(&$result, &$inner) {
        if (!$items) {
            $result[] = $perms;
        } else {
            foreach ($items as $i => $item) {
                $newItems = $items;
                $newPerms = $perms;
                array_splice($newItems, $i, 1);
                array_unshift($newPerms, $item);
                $inner($newItems, $newPerms);
            }
        }
    };
    $inner($list);
    return $result;
}
for ($i = 7; $i > 3; $i--) {
    $numbers = range(1, $i);
    $permutations = permute($numbers);
    rsort($permutations);
    foreach ($permutations as $numberArr) {
        $number = implode('', $numberArr);
        if (isPrime($number)) {
            DU::show($number);
            exit;
        }
    }
}
开发者ID:keune,项目名称:euler-solutions,代码行数:31,代码来源:41.php


示例19: parse_bbc


//.........这里部分代码省略.........
            }
            $pos1 = $pos + 1 + $pt_strlen + 1;
            // Quotes can have alternate styling, we do this php-side due to all the permutations of quotes.
            if ($possible['tag'] == 'quote') {
                // Start with standard
                $quote_alt = false;
                foreach ($open_tags as $open_quote) {
                    // Every parent quote this quote has flips the styling
                    if ($open_quote['tag'] == 'quote') {
                        $quote_alt = !$quote_alt;
                    }
                }
                // Add a class to the quote to style alternating blockquotes
                // @todo - Frankly it makes little sense to allow alternate blockquote
                // styling without also catering for alternate quoteheader styling.
                // I do remember coding that some time back, but it seems to have gotten
                // lost somewhere in the Elk processes.
                // Come to think of it, it may be better to append a second class rather
                // than alter the standard one.
                //  - Example: class="bbc_quote" and class="bbc_quote alt_quote".
                // This would mean simpler CSS for themes (like default) which do not use the alternate styling,
                // but would still allow it for themes that want it.
                $possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">'));
            }
            // This is long, but it makes things much easier and cleaner.
            if (!empty($possible['parameters'])) {
                $preg = array();
                foreach ($possible['parameters'] as $p => $info) {
                    $preg[] = '(\\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . ')' . (empty($info['optional']) ? '' : '?');
                }
                // Okay, this may look ugly and it is, but it's not going to happen much and it is the best way
                // of allowing any order of parameters but still parsing them right.
                $match = false;
                $orders = permute($preg);
                foreach ($orders as $p) {
                    if (preg_match('~^' . implode('', $p) . '\\]~i', substr($message, $pos1 - 1), $matches) != 0) {
                        $match = true;
                        break;
                    }
                }
                // Didn't match our parameter list, try the next possible.
                if (!$match) {
                    continue;
                }
                $params = array();
                for ($i = 1, $n = count($matches); $i < $n; $i += 2) {
                    $key = strtok(ltrim($matches[$i]), '=');
                    if (isset($possible['parameters'][$key]['value'])) {
                        $params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
                    } elseif (isset($possible['parameters'][$key]['validate'])) {
                        $params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
                    } else {
                        $params['{' . $key . '}'] = $matches[$i + 1];
                    }
                    // Just to make sure: replace any $ or { so they can't interpolate wrongly.
                    $params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '&#036;', '{' => '&#123;'));
                }
                foreach ($possible['parameters'] as $p => $info) {
                    if (!isset($params['{' . $p . '}'])) {
                        $params['{' . $p . '}'] = '';
                    }
                }
                $tag = $possible;
                // Put the parameters into the string.
                if (isset($tag['before'])) {
                    $tag['before'] = strtr($tag['before'], $params);
开发者ID:joshuaadickerson,项目名称:BBC-Parser,代码行数:67,代码来源:ParseBBC.php


示例20: sort_array

function sort_array(&$array1, &$array2)
{
    for ($i = 0; $i < sizeof($array1); $i++) {
        for ($j = 0; $j < sizeof($array1); $j++) {
            if ($array1[$i] > $array1[$j]) {
                permute($array1[$i], $array1[$j]);
                permute($array2[$i], $array2[$j]);
            }
        }
    }
}
开发者ID:Mohamed-ben-abda,项目名称:RSSCrawler,代码行数:11,代码来源:index.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP pfSenseHeader函数代码示例发布时间:2022-05-15
下一篇:
PHP perms2str函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap