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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:19:17+00:00 2026-05-27T05:19:17+00:00

Given a positive integer X , how can one partition it into N parts,

  • 0

Given a positive integer X, how can one partition it into N parts, each between A and B where A <= B are also positive integers? That is, write

X = X_1 + X_2 + ... + X_N

where A <= X_i <= B and the order of the X_is doesn’t matter?

  • 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-05-27T05:19:18+00:00Added an answer on May 27, 2026 at 5:19 am

    Here is a python solution to this problem, This is quite un-optimised but I have tried to keep it as simple as I can to demonstrate an iterative method of solving this problem.

    The results of this method will commonly be a list of max values and min values with maybe 1 or 2 values inbetween. Because of this, there is a slight optimisation in there, (using abs) which will prevent the iterator constantly trying to find min values counting down from max and vice versa.

    There are recursive ways of doing this that look far more elegant, but this will get the job done and hopefully give you an insite into a better solution.


    SCRIPT:

    # iterative approach in-case the number of partitians is particularly large
    def splitter(value, partitians, min_range, max_range, part_values):
        # lower bound used to determine if the solution is within reach
        lower_bound = 0
        # upper bound used to determine if the solution is within reach
        upper_bound = 0
        # upper_range used as upper limit for the iterator
        upper_range = 0
        # lower range used as lower limit for the iterator
        lower_range = 0
        # interval will be + or -
        interval = 0
    
        while value > 0:
            partitians -= 1
            lower_bound = min_range*(partitians)
            upper_bound = max_range*(partitians)
            # if the value is more likely at the upper bound start from there
            if abs(lower_bound - value) < abs(upper_bound - value):
                upper_range = max_range
                lower_range = min_range-1
                interval = -1
            # if the value is more likely at the lower bound start from there
            else:
                upper_range = min_range
                lower_range = max_range+1
                interval = 1
    
            for i in range(upper_range, lower_range, interval):
                # make sure what we are doing won't break solution
                if lower_bound <= value-i and upper_bound >= value-i:
                    part_values.append(i)
                    value -= i
                    break
    
        return part_values
    
    
    def partitioner(value, partitians, min_range, max_range):
        if min_range*partitians <= value and max_range*partitians >= value:
            return splitter(value, partitians, min_range, max_range, [])
        else:
            print ("this is impossible to solve")
    
    def main():
        print(partitioner(9800, 1000, 2, 100))
    

    The basic idea behind this script is that the value needs to fall between min*parts and max*parts, for each step of the solution, if we always achieve this goal, we will eventually end up at min < value < max for parts == 1, so if we constantly take away from the value, and keep it within this min < value < max range we will always find the result if it is possable.

    For this code’s example, it will basically always take away either max or min depending on which bound the value is closer to, untill some non min or max value is left over as remainder.

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

Sidebar

Related Questions

Given an integer n and a positive real number s, how can I partition
As a single operation between two positive integers we understand multiplying one of the
I had this question: Given an unsorted array of positive integers and an integer
Given an array of positive integer, we need to exchange each element with first
Given k positive integer numbers a 1 < a 2 < a 3 <
Given positive integers b, c, m where (b < m) is True it is
Here is the problem : Give a algorithm that takes a positive integer n
I have an optimization problem as follows. Given an array of positive integers, e.g.
Question: Given an unsorted array of positive integers, is it possible to find a
In this problem r is a fixed positive integer. You are given N rectangles,

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.