Link to home
Start Free TrialLog in
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )Flag for United States of America

asked on

Allocating items to a table

I need to allocate a fixed number of items to be placed on a variable number of tables. The number of tables is to be determined by the number of items, with these caveats:

1) There will always be at least 3 items. If there are fewer than 3 items, we cannot proceed

2) There can be no more than 6 items on any one table.

3) We wish to balance the number of items on a table. For example:

7 Items = 4 on one table, 3 on another
8 items = 4 on each table
9 items = 5 on one table, 4 on another
10 items = 5 on each
11 items = 6 on one table, 5 on another
12 items 6 on each table

And the issue would start back over at 13 only this time with 3 tables. We'd want something like 4 + 4 + 5.

Any suggestions on an algorithm, or coding for this? I can hard code it, and just build a matrix that supplies those values, but wondered if anyone had ideas on doing this a little differently.




Avatar of sshah254
sshah254

# of items = item1

item1 mod 12 should give you the remainder

int (item1 / 12) should give you the quotient

whatever is the quotient, distribute it equally in tables of 6

for the remainder, follow your logic with if/else or case statement.

Ss
Avatar of Imran Javed Zia
Hi,

Hope it will work for you

If items < 3
      Return
else If items < 13 Then
      Tables = 2
Else If Items/2=0 Then
      Tables = Items/6       // Just quotient
else
      Tables = (Items/6) + 1
End If

 

Initialize ArrayOfTable(Tables)

For i = 1 to items
      index = i Mod Tables
      Add Item to ArrayOfTable(index)      
Next


Print ArrayOfTable


Thanks
ASKER CERTIFIED SOLUTION
Avatar of TommySzalapski
TommySzalapski
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Scott McDaniel (EE MVE )

ASKER

Thanks for your responses, and sorry for the delay in responding - Easter weekend took more time than anticipated, so I'm a bit behind schedule.

I'll review, and post back here with my findings.
Thanks. This provided me with a very good basis for my algorithm.