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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:35:54+00:00 2026-06-03T08:35:54+00:00

I have an array / list of numbers. Each number has a certain priority

  • 0

I have an array / list of numbers. Each number has a certain priority / importance.

I need an algorithm that generate all combinations of numbers, but begin form numbers with the most importance.

e.g. [number, priority]: [1,1], [2,3], [3,2]. Highest priority is 1.

Combinations:

1, 3, 2, 1 1, 1 3, 3 3, 3 1, 1 2, 3 2, 2 1, 2 2, 1 1 1, 1 1 3, 1 3 1...

Any idea how to do this?
Of course, I want to generate a certain number of combinations.

  • 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-03T08:35:55+00:00Added an answer on June 3, 2026 at 8:35 am

    I changed my answer to an example code, this way you don’t even need a recursion. You have to sort first the elements by the priority. The example is in Perl, which is not so far from Pseudocode

    @numbers = (1, 3, 2, 4);
    
    push(@result, @numbers);
    push(@working_list, @numbers);
    for ($i = 1; $i < @numbers; $i++) {  # We loop exactly for the length of the array (-1 because the first iteration is already inside)
        my @result_list;
        for $result (@working_list) { # get the result of the last iteration of $i
            for $number (@numbers) { # iterate the numbers
                push (@result_list, "$result $number");  # adding the numbers
            }
        }
    
        push(@result, @result_list); # push the last result to final result list
        undef @working_list;
        push(@working_list, @result_list); # use the last result as a start point for next $i iteration
    
    }
    
    print join(', ', @result);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of images. Each image has a rarity key that tells
I have an array called $times . It is a list of small numbers
I have a list of Groups that can vary in number, with Items in
I have a series of array formulas in Excel that key off of each
Say I have a list of integers, where each element is a number from
I have a huge array of ints that I need to sort. The catch
I have a array.each function that calls a JSONP request for each item and
I have a dataset that is has a number of groups. I have to
I need to store an unknown number of groups. Each group has an unknown
Below is a PHP array I have, it has countries list 1 to 228

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.