Home More Samples
///////////////////////////////////////////////////////////////////////////////
//
// Title: Babysitting
// Author: Scott Marley
// Publication: Dell Logic Puzzles
// Issue: April, 1998
// Page: 7
// Stars: 1
//
// Each weekday, Bonnie takes care of five of the neighbors' children. The
// children's names are Keith, Libby, Margo, Nora, and Otto; last names are Fell,
// Gant, Hall, Ivey, and Jule. Each is a different number of years old, from two
// to six. Can you find each child's full name and age?
//
// 1. One child is named Libby Jule.
// 2. Keith is one year older than the Ivey child, who is one year older than Nora.
// 3. The Fell child is three years older than Margo.
// 4. Otto is twice as many years old as the Hall child.
//
///////////////////////////////////////////////////////////////////////////////
//
// query:
//          all Babysitting(lastname,age)
//
///////////////////////////////////////////////////////////////////////////////
//
// result:
//
// lastname = [ {Keith} Fell, {Libby} Jule, {Margo} Hall, {Nora} Gant, {Otto} Ivey]
//
// age      = [ {Keith} 5, {Libby} 6, {Margo} 2, {Nora} 3, {Otto} 4]
//
//
///////////////////////////////////////////////////////////////////////////////

Names = Keith | Libby | Margo | Nora | Otto
Lastnames = Fell | Gant | Hall | Ivey | Jule
Age = Names->>I[2..6]
Lastname = Names->>Lastnames

pred Babysitting(lastname::Lastname,age::Age) iff
{1} lastname(Libby) = Jule &
{2} age(Keith) = age(x) + 1 & lastname(x) = Ivey & age(x) = age(Nora) + 1 &
{3} lastname(y) = Fell & age(y) = age(Margo) + 3 &
{4} lastname(z) = Hall & age(Otto) = 2*age(z)