# Guests and Rooms - programming logic question

**URL:** <https://www.ruby-forum.com/t/guests-and-rooms-programming-logic-question/108432>\
**Category:** Rails\
**Created:** [July 3, 2007, 2:22pm UTC](https://www.ruby-forum.com/t/guests-and-rooms-programming-logic-question/108432 "2007-07-03T14:22:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jens](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d2c977/32.png) [@jens](https://www.ruby-forum.com/u/jens)\
**Post date:** [July 3, 2007, 2:22pm UTC](https://www.ruby-forum.com/t/guests-and-rooms-programming-logic-question/108432/1 "2007-07-03T14:22:13Z")

</div>

Hi everybody,

I am writing the registration and administration backend for a  
worldwide youth club organisation, which will expect about 12’000  
visitors next year on their meeting. For the activities and  
accommodation, these visitors need to be divided into groups of 15-17  
people according to certain criteria.

I’m hoping there is a way for Ruby (maybe Rails) to automate this  
task. Here are the rules:

- 15-17 people per group
- all people in one group must be have the same “age range” (13-17,  
28-25, 26-35, \>35 years). This is easy, just divide them by age range  
and treat each age range seperately.
- Siblings should not be seperated, and there should not be more than  
one family/sibling-pair in each group. This could be done by leaving  
out all users with a “sibling\_id” entered, and filling them in later.
- People who checked “Traveling together with …” in the application  
form should not be seperated. (same as above)
- There should be a mix of nationalities, but no language barriers in  
one group (ie. everybody must speak at least one common language).

and so on (some other rules aren’t fixed yet). I’m actually thinking  
to write a script that randomly distributes the people into groups and  
then takes all “invalid” groups and re-distributes the people in  
there, until all groups are OK by the above rules. But I guess coding  
the validation process is just as hard as coming up with a procedure  
that does this distribution in an “orderly” fashion, and is extensible  
with additional rules where necessary.

Any ideas would be great. I could perhaps code this in a dumb  
procedural fashion using lots of if, while, and for loops; but I kind  
of suspect that Ruby can do better than that.

Jens
