We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Allocating items to a table

Medium Priority
352 Views
Last Modified: 2012-05-11
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.




Comment
Watch Question

Commented:
# 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
Imran Javed ZiaConsultant Software Engineer - .NET Architect
CERTIFIED EXPERT

Commented:
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
CERTIFIED EXPERT
Awarded 2010
Top Expert 2013
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Scott McDaniel (EE MVE )Infotrakker Software
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Author

Commented:
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.
Scott McDaniel (EE MVE )Infotrakker Software
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Author

Commented:
Thanks. This provided me with a very good basis for my algorithm.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.