OpenRules Platform

Decision Optimization

Family Riddle

Model a family-relationship logic puzzle with constrained variables and declarative rules.

Problem Description. This problem is offered as a DMCommunity’s challenge Jan-2024.

children

Let’s assume that Rene and Leo are both heads of household, and, what a coincidence, both families include three girls and three boys. The youngest child in Leo’s family is a girl, and in Rene’s family, a little girl has just arrived. In other words, there is a girl in Rene’s family whose age is less than one year. Neither family includes any twins, nor any children closer in  age than a year. All the children are under age ten. In each family, the sum of the ages of the girls is equal to the sum of the ages of the boys; in fact, the sum of the squares of the ages of the girls is equal to the sum of the squares of the ages of the boys. The sum of the ages of all these children is 60.

QuestionWhat are the ages of the children in these two families? How many solutions has this problem?

Implementation. We will use the following business Glossary to describe the main concepts of the problem:

image

For every child in arrays ReneChildren and LeoChildren, Solver will create decision variables with possible values from 0 to 9 representing their ages.

We can represent both families in this DecisionData and DecisionTest tables:

Family Riddle illustration

We will use the standard Rule Solver top-level decision “DefineAndSolve”:

Family Riddle illustration

The table “Define” posts all constraints:

image

The table “Solve” finds and logs all possible solutions:

image

When we execute this decision model, we will receive one and only one solution:

image

Try Rule Solver

Build decision models that find the best answer.

Start with the free evaluation, then install Rule Solver and explore its optimization examples.