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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:30:24+00:00 2026-06-05T21:30:24+00:00

This is in regards to a problem for finding a number of combinations of

  • 0

This is in regards to a problem for finding a number of combinations of an ordered set, where the elements have constraints.

As an example:

a+b+c+d+e=635, which may be…

[0-90] + [1-120] + [50-150] + [20-200] + [30-250] = 635

One solution uses multiple summations, as it was answered in the mathematics stack exchange.

https://math.stackexchange.com/questions/159197/combinatorics-using-constraints-and-ordered-set

Can someone please give a general idea of the procedure or pseudo-code to solving this type of problem?

Thank you very much!

  • 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-05T21:30:26+00:00Added an answer on June 5, 2026 at 9:30 pm

    A bunch of nested for-loops is the simplest way to do it.

    Pseudocode:

    let combinations = 0;
    for a = 0 to 90
        for b = max(a+1, 1) to 120
            for c = max(b+1, 50) to 150
                for d = max(c+1, 20) to 200
                    let e = 635 - a - b - c - d;
                    if max(d+1, 50) <= e <= 250
                        let combinations = combinations + 1
    

    Update

    The above can be optimised a bit, but you end up with a specific, rather than general, solution.

    You can observe that (a+1) >= 1 is always true, so we can get rid of the max call in the assignment to b. Likewise, (c+1) >= 20 is always true, so the assignment to d can be simplified.

    You can also see that the maximum possible value of a + b + c + d is 540, which gives a minimum possible value of 95 for e. This is greater than the stated lower bound for e, so we just have to check that e >= (d+1).

    We end up with:

    let combinations = 0;
    for a = 0 to 90
        for b = a+1 to 120
            for c = max(b+1, 50) to 150
                for d = c+1 to 200
                    let e = 635 - a - b - c - d;
                    if d+1 <= e <= 250
                        let combinations = combinations + 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this problem in regards with default, since I m not sure whether
With regards this example from Code Complete: Comparison Compare(int value1, int value2) { if
I have just asked this question an hour ago but with regards to IE8
today I ran into this problem which really bugs me, as almost the code
Can some one please assist me in this example of TabHost? The problem i
I have a database that is uft8_general_ci, only problem is up until this point
Please help me on this problem. I have 2 identical tables, one is timetable
This is in regards to MS SQL Server 2005. I have an SSIS package
I have a problem regards the memory management of my game on Android 2.2.
I need some help in this problem I have this matrix in MATLAB: A

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.