Scott McDaniel (EE MVE )
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.
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.
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
I'll review, and post back here with my findings.
ASKER
Thanks. This provided me with a very good basis for my algorithm.
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