Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8239025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:00:23+00:00 2026-06-07T20:00:23+00:00

I’m doing a code that eliminates unneeded combinations such as I (ABCDE) do not

  • 0

I’m doing a code that eliminates unneeded combinations such as I (ABCDE) do not want AAA BBB AB BA only want ABC ABD ABE …. so on, want it to be valid for any situation, example code that I did work that way: he makes a set of combinations (1-6) 3 on 3 … but I want him funciane of (1-15) with combinations of 4 on 4 or 10 to 10 …. See the example for better understanding.

$lista = array(1,2,3,4,5,6);
$b=1;
for ($i=0; $i<=3; $i++) {
    for ($j=$b; $j<=4;$j++) {
    //  printf('valor do j = '.$j.'<br>');
        for ($k=$j+1; $k<count($lista); $k++) {
            printf($lista[$i].$lista[$j].$lista[$k].'<br>');
        }
    }
    $b++;
}

Result

123
124
125
126
134
135
136
145
146
156
234
235
236
245
246
256
345
346
356
456

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T20:00:26+00:00Added an answer on June 7, 2026 at 8:00 pm

    Original code: https://stackoverflow.com/a/2617080/661872 I just added $len part.

    <?php 
    // function to generate and print all N! permutations of $str. (N = strlen($str)).
    function permute($str,$i,$n,$len) {
        global $ret;
        if ($i == $n){
            if(in_array(substr($str,0,$len),$ret)==false){$ret[]=substr($str,0,$len);}
        }else {
            for ($j = $i; $j < $n; $j++) {
                swap($str,$i,$j);
                permute($str, $i+1, $n, $len);
                swap($str,$i,$j); // backtrack.
            }
        }
    }
    
    // function to swap the char at pos $i and $j of $str.
    function swap(&$str,$i,$j) {
        $temp = $str[$i];
        $str[$i] = $str[$j];
        $str[$j] = $temp;
    }
    $ret = array();
    $str = "123456";
    permute($str,0,strlen($str), 3); // call the function.
    
    
    print_r($ret);
    /**
     * Array
    (
        [0] => 123
        [1] => 124
        [2] => 125
        [3] => 126
        [4] => 132
        [5] => 134
        [6] => 135
        [7] => 136
        [8] => 143
        [9] => 142
        [10] => 145
        [11] => 146
        [12] => 153
        [13] => 154
        [14] => 152
        [15] => 156
        [16] => 163
        [17] => 164
        [18] => 165
        [19] => 162
        [20] => 213
        [21] => 214
        [22] => 215
        [23] => 216
        [24] => 231
        [25] => 234
        [26] => 235
        [27] => 236
        [28] => 243
        [29] => 241
        [30] => 245
        [31] => 246
        [32] => 253
        [33] => 254
        [34] => 251
        [35] => 256
        [36] => 263
        [37] => 264
        [38] => 265
        [39] => 261
        [40] => 321
        [41] => 324
        [42] => 325
        [43] => 326
        [44] => 312
        [45] => 314
        [46] => 315
        [47] => 316
        [48] => 341
        [49] => 342
        [50] => 345
        [51] => 346
        [52] => 351
        [53] => 354
        [54] => 352
        [55] => 356
        [56] => 361
        [57] => 364
        [58] => 365
        [59] => 362
        [60] => 423
        [61] => 421
        [62] => 425
        [63] => 426
        [64] => 432
        [65] => 431
        [66] => 435
        [67] => 436
        [68] => 413
        [69] => 412
        [70] => 415
        [71] => 416
        [72] => 453
        [73] => 451
        [74] => 452
        [75] => 456
        [76] => 463
        [77] => 461
        [78] => 465
        [79] => 462
        [80] => 523
        [81] => 524
        [82] => 521
        [83] => 526
        [84] => 532
        [85] => 534
        [86] => 531
        [87] => 536
        [88] => 543
        [89] => 542
        [90] => 541
        [91] => 546
        [92] => 513
        [93] => 514
        [94] => 512
        [95] => 516
        [96] => 563
        [97] => 564
        [98] => 561
        [99] => 562
        [100] => 623
        [101] => 624
        [102] => 625
        [103] => 621
        [104] => 632
        [105] => 634
        [106] => 635
        [107] => 631
        [108] => 643
        [109] => 642
        [110] => 645
        [111] => 641
        [112] => 653
        [113] => 654
        [114] => 652
        [115] => 651
        [116] => 613
        [117] => 614
        [118] => 615
        [119] => 612
    )
     */
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.