HomeHome More SamplesMore Samples
//////////////////////////////////////////////////////////////////////////////////////////////////
//
// Title: Teachers' Union
// Author: Thomas Mastriacovo
// Publication: Dell Logic Puzzles
// Issue: April, 1998
// Page: 40
// Stars: 4
// 
// The teachers at McKinley High School have elected a team of five teachers (three women named 
// Gena, Lisa, and Marie, and two men named David and Walt) to act as their representatives to the
// union. Each has a different whole number of years of teaching experience. During a recent 
// contract dispute, each took on a different role (administrative support person, faculty liaison,
// media liaison, negotiation team leader, or union delegate). 
//
// Can you discover each person's full name (surnames are Foroutan, Hammond, Offenberg, Suzumi, 
// and Zapf), number of years of teaching experience, and role during the dispute?
// 
//  1. Of the three women, the one with the most experience has eleven years.
//  2. Marie (who isn't surnamed Foroutan) has one more year of experience than Walt; one of them 
//     was the administrative support person.
//  3. Gena and the person with seven years of experience are, in some order, Suzumi and the person
//     with the fourth-most years of experience.
//  4. Lisa has one more year of experience than Suzumi.
//  5. No one has exactly nine or twelve years of experience.
//  6. At least one woman was hired between the two men.
//  7. Zapf has more experience than the negotiation team leader.
//  8. The union delegate has at least three more years of experience than the media liaison.
//  9. When the five representatives are listed in order of experience, David Hammond and Gena are
//     not consecutive in either order. 
// 10. Foroutan has either two more or two fewer years of experience than another teacher.
// 
///////////////////////////////////////////////////////////////////////////////////////////////////
//
// Query: 
//          TeachersUnionSolutions() 
//
///////////////////////////////////////////////////////////////////////////////////////////////////
//
// Result:
//
// Number of solutions:1
// Teacher = [ {Gena} Suzumi, {Lisa} Foroutan, {Marie} Zapf, {David} Hammond, {Walt} Offenberg]
// Role =    [ {Administrative_support_person} Marie, {Faculty_liaison} Lisa, {Media_liaison} Gena, 
//             {Negotiation_team_leader} Walt, {Union_delegate} David]
// Years =   [ {Gena} 10, {Lisa} 11, {Marie} 7, {David} 13, {Walt} 6]
//
///////////////////////////////////////////////////////////////////////////////////////////////////
//
// Notes: 
//      1. The clues never explicitely specify the maximum number of years of experience.
//         However, the clue 5 suggests that somebody has more than twelve years of experience.
//         Without this constraint there are 12 distinct solutions.
//
//      2. The query "all TeachersUnion(teacher,role,years)" results in multiple identical 
//         solutions. To avoid displaying all the identical solutions, we collect them all in the 
//         proc TeachersUnionSolutions.
//
///////////////////////////////////////////////////////////////////////////////////////////////////

local Surname = Foroutan | Hammond | Offenberg | Suzumi | Zapf
local Name = Gena | Lisa | Marie | David | Walt

local Role = Administrative_support_person | Faculty_liaison | Media_liaison | 
             Negotiation_team_leader | Union_delegate

Teachers = Name->>Surname
Years = Name->>L[1..]       // Note: no upper bound on years of experience
Roles = Role->>Name

///////////////////////////////////////////////////////////////////////////////////////////////////
//
proc TeachersUnionSolutions() iff
    // Collect all solution into a list of solutions "allsolutions"
    all teacher,role,year in allsolutions 
        TeachersUnion(teacher,role,year) 
    end & 

    // Length of the list of all solutions is the number of distinct
    // solutions.

    Print(_pred,'\nNumber of solutions: ',Len(allsolutions),'\n') &
    PrintSolutions(allsolutions)

local proc PrintSolutions(l:<list(teacher:Teachers,role:Roles,years:Years)) iff
    if l = h,t then
        r = l.h & r = teacher,role,years & 
        Print('\nTeacher = ',teacher) &
        Print('\nRole =    ',role) &
        Print('\nYears =   ',years,'\n\n') & PrintSolutions(t)
    end 

///////////////////////////////////////////////////////////////////////////////////////////////////
//
//
pred TeachersUnion(teacher::Teachers,role::Roles,years::Years) iff

//  1. Of the three women, the one with the most experience has eleven years.
    IsWoman(woman1) &
    IsWoman(woman2) & woman1 <> woman2 &
    IsWoman(woman3) & woman1 <> woman3 & woman2 <> woman3 &
    years(woman1) = 11 & years(woman2) < 11 & years(woman3) < 11 &

//  2. Marie (who isn't surnamed Foroutan) has one more year of experience than Walt; one of them
//     was the administrative support person.
    teacher(Marie) <> Foroutan &
    years(Marie) = years(Walt) +1  & 
    (role(Administrative_support_person) = Marie | role(Administrative_support_person) = Walt) & 

//  3. Gena and the person with seven years of experience are, in some order, Suzumi and the person
//     with the fourth-most years of experience.
    years(Gena) <> 7 &
    years(person_with_seven_years_of_experience) = 7 &
    Suzumi = teacher(suzumi) &
    ((suzumi = Gena & FourthOldest(years,person_with_seven_years_of_experience)) | 
     (FourthOldest(years,Gena) & suzumi = person_with_seven_years_of_experience))  &

//  4. Lisa has one more year of experience than Suzumi.
    Suzumi = teacher(suzumi) &
    years(Lisa) = years(suzumi) + 1 &

//  5. No one has exactly nine or twelve years of experience.
    ~9 in years & ~12 in years &
    years(_) > 12 &      // 12 distinct solutions without this constraint 

//  6. At least one woman was hired between the two men.
    years(woman) = ywoman & IsWoman(woman) & 
    years(man1) = yman1 & IsMan(man1) & 
    years(man2) = yman2 & IsMan(man2) & man1 <> man2 &
    ywoman > yman1 & ywoman < yman2 &

//  7. Zapf has more experience than the negotiation team leader.
    Zapf = teacher(zapf) & years(zapf) > years(role(Negotiation_team_leader)) &

//  8. The union delegate has at least three more years of experience than the media liaison.
    years(role(Union_delegate)) >= years(role(Media_liaison)) + 3 & 

//  9. When the five representatives are listed in order of experience, David Hammond and 
//     Gena are not consecutive in either order. 

    teacher(David) = Hammond & 
    years(Gena) <> years(David) + 1 & years(Gena) <> years(David) - 1 & 

// 10. Foroutan has either two more or two fewer years of experience than another teacher.
    Foroutan = teacher(foroutan) &
    (years(foroutan) = years(_) + 2 | years(foroutan) = years(_) - 2)


///////////////////////////////////////////////////////////////////////////////////////////////////
// There are three people with more experience and one person with less 
// experience 
//
local pred FourthOldest(years::Years,name::Name) iff 
    years(x1) = y1 &
    years(x2) = y2 & x2 <> x1 &
    years(x3) = y3 & x3 <> x2 & x3 <> x1 &
    years(name) = y4 &
    years(x5) = y5 & 
    y4 < y3 & y4 < y2 & y4 < y1 & y4 > y5

local pred IsWoman(x::Name) iff
    x = Gena | x = Lisa | x = Marie

local pred IsMan(x::Name) iff
    x = David | x = Walt




This page was created by F1toHTML