Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

convert letters to digits and get all combinations

HrachHrach YerevanPosts: 2
edited April 2016 in PHP

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

Quote:
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'));

123
213
132
312
231
321

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.

Tagged:

Comments

  • HrachHrach YerevanPosts: 2

    @Hrach said:
    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

    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'));

    123
    213
    132
    312
    231
    321

    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.

Sign In or Register to comment.