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

  • Home
  • SEARCH
  • 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 7874451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:48:30+00:00 2026-06-03T02:48:30+00:00

Possible Duplicate: Algorithm to return all combinations of k elements from n Generate Distinct

  • 0

Possible Duplicate:
Algorithm to return all combinations of k elements from n
Generate Distinct Combinations PHP

I have an array containing a number of characters/letter,s e.g:

$seed = array('a','b','c','d','e','f',.....,'z','1','2','3',...'9');

I want to get all possible unique 4 character combinations/permutations from the seed, for example:

abcd, azxy, ag12, aaaa, etc

What’s the best way to accomplish this?

I have thought about dividing the seed array into 4 letter groups, then go through each group and generate all possible combinations of that group, but that will leave out many combinations (i.e it will process abcd and wxyz, but not abyz and wxcd)

  • 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-03T02:48:31+00:00Added an answer on June 3, 2026 at 2:48 am

    For each character in the array, write that character followed by each of the unique 3 character strings either from the characters after it (if you actually mean combinations) or from all the characters (which is what I think you mean).

    How to generate all unique 3 character permutations of a seed string?

    See this very similar question.

    You may also want to read about recursion.

    Python code

    >>> def product(chars, n):
            if n == 0:
                yield ''
            else:
                for c in chars:
                    for result in product(x, n - 1):  # Recursive call
                        yield c + result
    
    >>> list(product(['a', 'b', 'c'], 2))
    ['aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc']
    

    (Note: in real Python code you should use itertools.product rather than writing it yourself.)

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

Sidebar

Related Questions

Possible Duplicate: Algorithm for generating a random number is posible to generate a random
Possible Duplicate: Generating all Possible Combinations I'm trying to do a little algorithm in
Possible Duplicate: optimal algorithm for finding unique divisors I have asked this question before,
Possible Duplicate: Interview Q: given an array of numbers, return array of products of
Possible Duplicate: Best algorithm to count the number of set bits in a 32-bit
Possible Duplicate: Algorithm to find Lucky Numbers I came across this question.A number is
Possible Duplicate: Algorithm to find minimum number of weighings required to find defective ball
Possible Duplicate: Best algorithm to count the number of set bits in a 32-bit
Possible Duplicate: Best algorithm to count the number of set bits in a 32-bit
Possible Duplicate: Finding a single number in a list Given an array of numbers,

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.