Possibilities and nested foreach loops C# -


i writing program can calculate possible places people sitting @ random amount of tables (can go 1000+):

enter image description here

as see on image, black dots represent people (but in computer, there different types of people.) there 2 types of tables : blue , pink ones. blue ones can contain 3 people , pink 2 people.

to possible places person sit use foreach loops (8of them) , can run code...

but happens if add 200 tables? need use 200 foreach loops? there way can coded faster , less-space-consuming-coded?

what tried? =>

  switch(listoftables.count)   {       case 1:foreach(table table in listoftables){ //code add people table}break;       case 2: foreach(table table1 in listoftables)       {foreach(table table1 in       listoftables){//code add people table    }}break;    } 

input : array editable table class objects (its class created myself) process : above list edited , added list object, after whole foreach process has ended, output write possible configurations (who in other list object) screen.

example part of output :

  // list<table> listofalltables processed   list<listofalltables> output  

=> contains [0] in array : list first => contains [0] in array : table.attachedpeople (is list)

try recursive method. small example :

public list<table> assigntotable(list<person> invited, list<table> tables) {     if(!tables.hasroom)          return tables;      else      {          assign(tables,invited) //code add person table          assigntotable(invited, tables);      } } 

if i'll create object taht represent tables propertie know if there still room avaiblable. assign every people table without foreach. in main have method rearrange tables in way possible : table 1 table 2 table 3

then

table 1 table 3 table 2 ...

table 3 table 2 table 1

and call recursive method on lists , have possibility poeple can sit...


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -