算法将字母转换为数字,并在PHP递增中获得所有组合,直到9。 [英] Algorithm convert letters to digits and get all combinations in PHP incrementing untill 9.

查看:79
本文介绍了算法将字母转换为数字,并在PHP递增中获得所有组合,直到9。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在字符串中有字母,我希望在结果中获取所有这些字母的可能集合并将它们转换为数字,每个集合应该使用所有数字,每个数字只能在一个集合中出现一次。数字自动增加到9并输出所有可能的组合



I have letters in a string, I would like in result get all possible sets of those letters and convert them to numbers, each set should use all numbers, each number can occur only once in a set. numbers automatically should increment until 9. and output all possible combinations

<blockquote class="quote"><div class="op">Quote:</div>function pc_permute($items, $perms = array( )) {
    
    if (empty($items)) { 
      // var_dump(join($perms));
        echo join($perms) . "\n";
       // var_dump(join($perms));
    }  else {
       
        for ($i = count($items) - 1; $i >= 0; --$i) {             
             $newitems = $items;
             var_dump($newitems);
             $newperms = $perms;
             var_dump($newperms);
             list($foo) = array_splice($newitems, $i, 1);            
             array_unshift($newperms, $foo);
             pc_permute($newitems,$newperms);//, $newperms);
         }
    }
}
pc_permute(array('1','2','3')); </blockquote>





布局是



Outup is

引用:



123

213

132

312

231

321


123
213
132
312
231
321







我需要获得所有组合加增加到9,例如,如果输出是'333abc'



输出将是

333012

333052

333654

333162

333458

等等..直到789因为需要检查不重复的字母。



我的尝试:



pc_permute($ items, $ perms = array()){



if(empty($ items)){

// var_dump(join($ perms) );

echo join($ perms)。 \ n;

// var_dump(加入($ perms));

}否则{



for($ i = count($ items) - 1; $ i> = 0; - $ i){

$ newitems = $ items;

var_dump($ newitems);

$ newperms = $ perms;

var_dump($ newperms);

list($ foo)= array_splice( $ newitems,$ i,1);

array_unshift($ newperms,$ foo);

pc_permute($ newitems,$ newperms); //,$ newperms);

}

}

}

pc_permute(数组('1','2','3'));




I need to get all combinations plus incrementng till 9, for example if output is '333abc'

output would be
333012
333052
333654
333162
333458
and so on.. untill 789 because need to check for letters not to repeat.

What I have tried:

pc_permute($items, $perms = array( )) {

if (empty($items)) {
// var_dump(join($perms));
echo join($perms) . "\n";
// var_dump(join($perms));
} else {

for ($i = count($items) - 1; $i >= 0; --$i) {
$newitems = $items;
var_dump($newitems);
$newperms = $perms;
var_dump($newperms);
list($foo) = array_splice($newitems, $i, 1);
array_unshift($newperms, $foo);
pc_permute($newitems,$newperms);//, $newperms);
}
}
}
pc_permute(array('1','2','3'));

推荐答案

items,


perms = array()){

if(empty(
perms = array( )) { if (empty(


items)){
// var_dump(join(
items)) { // var_dump(join(


这篇关于算法将字母转换为数字,并在PHP递增中获得所有组合,直到9。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆