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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:32:26+00:00 2026-06-06T16:32:26+00:00

Abstract: You select the modules you are registered for. Each module has a number

  • 0

Abstract:

You select the modules you are registered for.

Each module has a number of groups.

Each group represents lectures for the given module.

Each combination should contain only one group from each module.

Example:

COS 121 -3 Groups

COS 132 -2 Groups

This will give you 6 options: [1,1],[1,2],[2,1],[2,2],[3,1],[3,2]

My angle:
I need to use each combination to generate the timetable, so I use an array which stores the current group being used and the total number of groups: arrSubjects[subject,currentGroup,maxGroups]

Logically you should be able to iterate through this array to make use of each combination of groups.

I just can’t get the grasp of this solution, maybe because I’m using the wrong angle. Any help/suggestions would really be appreciated.

My current implementation:
I’m quite embarrassed about this, because it takes a lot of time, but it works.
Here’s the basic in pseudo-code:

for (all the groups multiplied with eachother) do {
  for (all the modules selected) do {
    Select a random group between 1 and the nmr of groups 
  }
}

After which I have to get rid of all the duplicates.

Thanks in advance

The code I’m currently working on:

arrPermutations[0,0]:=1;//Current group for 1st module
arrPermutations[0,1]:=3;//Max groups for 1st module
arrPermutations[1,0]:=1;
arrPermutations[1,1]:=3;
arrPermutations[2,0]:=1;//Current group for 3rd module
arrPermutations[2,1]:=3;//Max groups for 3rd module
iCurrent:=iMax; //2
while (arrPermutations[0,0]<=arrPermutations[0,1]) do
begin
//Display arrPermutations
if arrPermutations[iCurrent,0]=arrPermutations[iCurrent,1] then
begin
  Inc(arrPermutations[iCurrent-1,0]);
  for i := iCurrent to iMax do
    arrPermutations[i,0]:=1;
  iCurrent:=iMax;
end else
begin
  Inc(arrPermutations[iCurrent,0]);
end;
end;

Currently I’m only traversing through the last two groups.
Here’s the output I get when checking:

============Run 1==============

module,current group,max groups

1,1,3

2,1,3

3,1,3

============Run 2==============

module,current group,max groups

1,1,3

2,1,3

3,2,3

============Run 3==============

module,current group,max groups

1,1,3

2,1,3

3,3,3

============Run 4==============

module,current group,max groups

1,1,3

2,2,3

3,1,3

============Run 5==============

module,current group,max groups

1,1,3

2,2,3

3,2,3

============Run 6==============

module,current group,max groups

1,1,3

2,2,3

3,3,3

============Run 7==============

module,current group,max groups

1,1,3

2,3,3

3,1,3

============Run 8==============

module,current group,max groups

1,1,3

2,3,3

3,2,3

============Run 9==============

module,current group,max groups

1,1,3

2,3,3

3,3,3

============Run 10==============//////Here is the problem

module,current group,max groups

1,1,3

2,4,3

3,1,3

  • 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-06T16:32:28+00:00Added an answer on June 6, 2026 at 4:32 pm

    NEW ANSWER:

    First, the number of possible combinations is the product of the number of groups in each module. For example, if there are three modules, contaning 5, 2, and 7 groups respectively, then there are 5*2*7 = 70 possible combinations. Call this TOTALCOMBOS.

    So, if you want to iterate through all the possible combinations, you can just loop from 0 to TOTALCOMBOS-1.

    for I in 0..TOTALCOMBOS-1 do
        COMBO = (convert I to a combination)
        (do something with COMBO)
    

    Now, to convert the index into a combination, it helps to think of the integer index as a list of “digits” from right to left. This is easiest to see if there are ten groups per module, and if group numbers start at 0 instead of 1. Then an integer 468 could be read as the list (8,6,4), which means group 8 from module 1, group 6 from module 2, and group 4 from module 3. In pseudocode, converting an index to a combination would be something like

    DIGITS = I
    for M in 1..(number of modules) do
       D = DIGITS mod (number of groups in module M)
       DIGITS = DIGITS / (number of groups in module M)
       (add group D from module M to the current combination)
    

    If you want group numbers to start at 1 instead of 0, then just use group D+1 in the last line, instead of group D.

    OLD ANSWER:

    Use recursion. The recursive function can take a list of modules, and return a list of combinations. Each combination will contain one group from each module in the input list.

    As the base case, if the list of modules is empty, return an empty list of combinations.

    Otherwise, let M be the first module, and let REST be the rest of the modules. Call the recursive function on REST to get all combinations of the rest of the modules (call this list of combinations COMBOS). Note that these combinations in COMBOS do not contain groups from M.

    Now, we’ll make a list of all the combinations, this time including the groups from M. Initialize a list ANSWERS to empty. Use two nested loops. For each group G in M, and for each combination C in COMBOS, add G to C, and add this extended combination to ANSWERS.

    Return ANSWERS.

    (Assumptions: No group appears in more than one module, or in the same module twice. No module appears in the list of modules more than once. You can relax these assumptions if you want, but you would need to define what you wanted the behavior to be in these cases.)

    (Comment 1: I said “list” above, but all these lists could just as easily be arrays or some other kind of container.)

    (Comment 2: Where I said “add G to C”, it is important that C itself not be changed, because it will be re-used many times, once for each group in M.)

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

Sidebar

Related Questions

I have an sqlite union query: SELECT term,abstract, termid, nterm FROM (SELECT term, subterm,
SELECT * WHERE { <http://dbpedia.org/resource/People%27s_Republic_of_China> <http://dbpedia.org/ontology/abstract> ?abstract . FILTER (lang(?abstract)='en') } but if I
Abstract What I require is a technique, given a single, but layered Flash animation,
I hope anyone can translate my abstract query. I want to select * from
Is it possible to select all controls that inherit a particular abstract class with
I have a toggle buttons group with 4 different pointers When I select the
In my domain model I have an abstract class CommunicationChannelSpecification, which has child classes
ODS List is a collection of abstract classes that implement a filtered select method
Ok, here we go... I have a select query accessing a very abstract database.
Given this snippet of code public abstract class Foo { private static SqlConnection _sqlConnection;

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.