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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:54:25+00:00 2026-06-05T16:54:25+00:00

I have several different numbers in a group that range in sizes and would

  • 0

I have several different numbers in a group that range in sizes and would like to calculate which group the numbers should go in based on the max size the group can be.

Example of the numbers: 10,20,30,40,50,60

Example of conditions: the maximum total the numbers can add up to in a group
is 60

So from the example above the answer would be:

group 1 would have the numbers 10,20,30

group 2 would have the number 40

group 3 would have the number 50

group 4 would have the number 60

Is there a way in matlab/octave or excel/librecalc this can be computed?

PS: A group can also have the number 40 and 20 the group total just can’t go over 60. But they can only use each number once.

Is there a math term used for this?

  • 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-05T16:54:27+00:00Added an answer on June 5, 2026 at 4:54 pm

    EDIT:

    The solution below uses a brute-force approach to generating powersets of powersets (although trimmed). Then checks for groups that satisfy the conditions set (namely divide all the numbers into groups such that no group contain a sum of more than 60). I borrowed some code from the powerset.m function in PMTK3 toolbox.

    This should work fine for a small problem like this one, but I suspect it would grow exponentially in size for larger input. I’m sure there are better heuristic/algorithms out there, so take this as a starting point…

    %# set of numbers
    S = [10,20,30,40,50,60];
    
    %# powerset of S (exclude empty set)
    b = (dec2bin(2^numel(S)-1:-1:1) == '1');
    P = cellfun(@(idx)S(idx), num2cell(b,2), 'UniformOutput',false);
    
    %# keep only sets where the sum is at most 60
    P = P(cellfun(@sum,P) <= 60);
    
    %# take the powerset of the powerset, although we can
    %# reduce it to no more than numel(S) subsets in each.
    %# The idea here is: nchoosek(p,1:numel(s))
    b = (dec2bin(2^numel(P)-1:-1:1) == '1');
    b = b(sum(b,2)<=numel(S),:);
    PP = cellfun(@(idx)P(idx), num2cell(b,2), 'UniformOutput',false);
    
    %# condition: every number appears exactly once in groups
    ppp = cellfun(@(x) [x{:}], PP, 'UniformOutput',false);
    idx = find(cellfun(@numel,ppp) == numel(S));
    idx2 = ismember(sort(cell2mat(ppp(idx)),2), S, 'rows');
    PP = PP( idx(idx2) );
    
    %# cleanup, and show result
    clearvars -except S PP
    celldisp(PP)
    

    This gave me 12 solutions. For example:

    >> PP{1}{:}
    ans =
        10    20    30
    ans =
        40
    ans =
        50
    ans =
        60
    
    >> PP{6}{:}
    ans =
        10    40
    ans =
        20
    ans =
        30
    ans =
        50
    ans =
        60
    
    >> PP{12}{:}
    ans =
        10
    ans =
        20
    ans =
        30
    ans =
        40
    ans =
        50
    ans =
        60
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several different content type nodes (videos, image galleries, stories...) that I would
In my game application I have several different activities that all can be accessed
Hi i'm trying to create a league table in which i have several different
I have a large class, which I have divided into several different class extension
I have several different input files, saved with case numbers .1, .2, etc to
In a range where different columns may have different numbers of values (but there
I have several tables with different numbers and types of columns, and a single
I have several different lists I want to call. They all have the same
I have several objects of different kinds (different function names, different signatures) and I
I have several sites in different domains: example.com , example.org , mail.example.com and passport.example.org

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.