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 8814121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:01:42+00:00 2026-06-14T04:01:42+00:00

Based on this question Ordered Fixed Length Combination of a String I created a

  • 0

Based on this question

Ordered Fixed Length Combination of a String

I created a PHP algorithm that creates combinations of characters on a fixed length (basically a rewrite of the Java-answer)

private function getCombination($length, $input) {
    $result = array();

    if ($length == 0) {
        return $result;
    }

    $first = substr($input, 0, $length);
    $result[] = $first;

    if (strlen($input) == $length) {
        return $result;
    }

    $tails = $this->getCombination($length - 1, substr($input, 1));

    foreach ($tails as $tail) {
        $tmp = substr($input, 0, 1) . $tail;

        if (!in_array($tmp, $result)) {
            $result[] = $tmp;
        }
    }

    return array_merge($result, $this->getCombination($length, substr($input, 1)));
}

For another question, Create fixed length non-repeating permutation of larger set, I was given a (brilliant) algorithm that would make permutations indexable, effectively making them adressable by providing a “key” that would always produce the exact same permutation, when given the same set of characters and the same length.

Well, now I basically need the same but for combinations, in contrast to permutations as in my other question.

Can the algorithm above be modified in the same way? Meaning to create a function like

public function getCombinationByIndex($length, $index);

That will return one combination out of the thousand possible that is created with the algorithm without creating them beforehand?

  • 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-14T04:01:43+00:00Added an answer on June 14, 2026 at 4:01 am

    I have written a class in C# to handle common functions for working with the binomial coefficient, which is the type of problem that your problem appears to fall under – assuming that you working with combinations instead of permutations. It performs the following tasks:

    1. Outputs all the K-indexes in a nice format for any N choose K to a file. The K-indexes can be substituted with more descriptive strings or letters.

    2. Converts the K-indexes to the proper index of an entry in the sorted binomial coefficient table. This technique is much faster than older published techniques that rely on iteration. It does this by using a mathematical property inherent in Pascal’s Triangle.

    3. Converts the index in a sorted binomial coefficient table to the corresponding K-indexes. I believe it is also faster than older iterative solutions.

    4. Uses Mark Dominus method to calculate the binomial coefficient, which is much less likely to overflow and works with larger numbers.

    5. The class is written in .NET C# and provides a way to manage the objects related to the problem (if any) by using a generic list. The constructor of this class takes a bool value called InitTable that when true will create a generic list to hold the objects to be managed. If this value is false, then it will not create the table. The table does not need to be created in order to use the 4 above methods. Accessor methods are provided to access the table.

    6. There is an associated test class which shows how to use the class and its methods. It has been extensively tested with 2 cases and there are no known bugs.

    To read about this class and download the code, see Tablizing The Binomial Coeffieicent.

    It should be pretty straight forward to port this class over to php. You probably will not have to port over the generic part of the class to accomplish your goals. Denending on the number of combinations you are working with, you might need to use a bigger word size than 4 byte ints.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Based on this question I've created a small application which is catching all debug
edit : I based this question on a false assumption - that the generic
Based on this question it appears that the default template for CheckStyle will allow
Based on this question I understand the purpose of the construct in linking C
Based on this question How to insert array into mysql using PDO and bindParam?
This question is based on this thread . Is [---] a comment in Git
This question is based on this thread . I am interested in how Git
This question is based on this thread . The code function man() { man
This question is based on this thread in Meta . I would like to
This question is based on this thread . Problem: to access MySQL's manual when

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.