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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:03:33+00:00 2026-06-01T04:03:33+00:00

Context I have a list of items I also have a structure with s

  • 0

Context

  • I have a list of items
  • I also have a structure with s stages
  • The number of stages of stages can be larger, equals or less than the number of items
  • Each stage can have n slots
  • Items can ocupy the same stage by take 2 slots in that stage
  • The slots’ order is irrelevant
  • The number of slots is less or equal to the number items
  • Each slot can contain one item
  • A slot can be empty
  • Any given structure can only contain each item once

Problem:

I want to generate all the combinations for the distribution of items in structure, such that:

  • Each item appears once and only once in the structure
  • All items are present in each combination
  • I want to use Java for the implementation

Example:

/* Inputs */
items = {1, 2}
structure = [ {}, {}, {}] // with 3 stages

/* Outputs */
comb1 = [ {1,2}, {}, {} ]
comb2 = [ {1}, {2}, {} ]
comb3 = [ {1}, {}, {2} ]
comb4 = [ {}, {1,2}, {} ]
comb5 = [ {}, {1}, {2} ]
comb6 = [ {}, {}, {1,2}]
comb7 = [ {}, {2}, {1} ]
comb8 = [ {2}, {1}, {} ]
comb9 = [ {2}, {}, {1} ]

Ideas are extremely welcome.

  • 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-01T04:03:34+00:00Added an answer on June 1, 2026 at 4:03 am

    here is the solution:

    import time
    
    
    def get_stages(size):
       stages = []
       for i in range(0, size):
          stages.append([])
       return stages
    
    def get_combos(combo_size, stage_size):
       combos = []
       for i in range(0, combo_size):
          combos.append(get_stages(stage_size))
       return combos
    
    
    def insert_item_in_stage(stages, position, item):
       stages[position].append(item)
    
    def copy_stages(stages):
       #print 'copying', stages
       copies = []
       for i in range(0, len(stages)):
          copy = []
          for stage in stages:
             stage_copy = []
             for slot in stage:
                stage_copy.append(slot)
             copy.append(stage_copy)
          copies.append(copy)
       return copies
    
    def combine(items, stages, all_combos):
       #print items, 'with', stages
       if len(items) == 1:
          item = items[0]
          combos = copy_stages(stages)
          for combo in combos:
             combo[combos.index(combo)].append(item)
             all_combos.append(combo)
       elif len(items) > 1:
          item = items[0]
          items.remove(item)
          combos = copy_stages(stages)
    
          for combo in combos:
             combo[combos.index(combo)].append(item)
             combine(list(items), combo, all_combos)
       else:
          print 'oops'
    
    
    def test (items, size):
       print 'test', items, 'with', size, "stages"
       stages = get_stages(size)
       all_combos = []
       combine(items, stages, all_combos)
       for combo in all_combos:
          print combo
       print len(all_combos)
       print ''
    
    #run tests
    test([1,2], 3)
    test([1,2,3], 3)
    start =  time.clock()
    test([1,2,3,4,5, 6], 8)
    end = time.clock()
    print end-start
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of content items, each with a set width but different
I have a list view filled with data. I set up a context menu
I have a button which opens a context menu with a list of various
I'm working on 'timeline' project, where I have content inside of list items, in
I have a module, that is just a list of items. Relating to content.
I have a list of items with some details that I would like to
I have a query pulling from a database: List<myClass> items = new List<myClass>(from i
I have a list which I have obtained from a python script. the content
I have a SharePoint list with Content Approval enabled. The business requirement is that
I have an initialization class that preloads content into a variable (probably a list

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.