HomeHome More SamplesMore Samples
///////////////////////////////////////////////////////////////////////////////
//
// Title: Cheese and Crackers
// Author: Marion McDee
// Publication: Dell Logic Puzzles
// Issue: February, 2000
// Page: 48
// Stars: 5
// 
// Each Wednesday evening, Julie and five of her friends get together to play
// cards and break up the tedium of the work week. Last week, Julie hosted the
// gathering, and as her favorite deli was having a cheese sale, Julie selected
// six varieties (including Swiss) to serve as a snack, along with six flavors 
// of crackers (including cumin seed crackers). In addition, Julie set out three
// kinds of fruit (apples, oranges, and pears) and three beverages (coffee, milk,
// and tea) on trays near the card table. When each friend settled in for the 
// game, no two had chosen the same variety of cheese or cracker, and no one had
// selected more than one kind of fruit or beverage (at least one person chose 
// each kind of fruit and beverage). 
// From the following information, can you match each woman with the type of 
// cheese, cracker, fruit, and beverage she enjoyed during the card game?

// 1. The six women are one who ate an apple, the person who sampled the
//    Roquefort cheese, a woman who drank milk, a woman who sipped coffee, 
//    another woman who drank coffee, and a woman who chose tea.
// 2. The six women are a woman who drank tea, a woman who ate a pear, a person 
//    who drank coffee, another woman who ate a pear, the friend who chose the 
//    dill seed crackers, and another woman who sipped coffee.
// 3. The six women are one who drank coffee, the woman who ate celery seed
//    crackers, the friend who selected the Tilsit cheese, another woman who 
//    drank coffee, a woman who drank tea, and a woman who ate an apple.
// 4. The six women are one who chose coffee, a friend who ate an apple, a 
//    friend who chose a pear, the one who ate the Muenster cheese, the woman 
//    who ate the caraway seed crackers, and the person who enjoyed the poppy 
//    seed crackers.
// 5. The six women are a person who had tea, the woman who ate feta cheese, 
//    a person who had coffee, a woman who had an apple, another woman who had 
//    tea, and another woman who chose an apple.
// 6. The six women are one who ate an apple, the woman who chose the Edam 
//    cheese, a woman who sampled a pear, a woman who sipped coffee, another 
//    woman who had an apple, and the one who selected the sesame seed crackers.
// 7. In one of the sequences in clues 1 through 6, the women are listed in the
//    following order: Julie, Miriam, Olive, Rosa, Selena, and Winnie.
// 8. In one of the sequences in clues 1 through 6, the women are listed in the
//    following order: Winnie, Selena, Rosa, Olive, Miriam, and Julie.
// 9. In one of the sequences in clues 1 through 6, the women are listed in the 
//    following order: Julie, Olive, Selena, Miriam, Rosa, and Winnie.
//10. In one of the sequences in clues 1 through 6, the women are listed in the 
//    following order: Olive, Miriam, Julie, Winnie, Selena, and Rosa.
//11. In one of the sequences in clues 1 through 6, the women are listed in the 
//    following order: Julie, Olive, Miriam, Selena, Rosa, and Winnie.
//12. In one of the sequences in clues 1 through 6, the women are listed in the 
//    following order: Miriam, Winnie, Olive, Rosa, Julie, and Selena.
//
// Determine: Woman - Cheese - Cracker - Fruit - Beverage
//
///////////////////////////////////////////////////////////////////////////////
//
// Query:
//
//          CheeseAndCrackerSolutions()
//
///////////////////////////////////////////////////////////////////////////////
//
// Result:
//
// Number of solutions:1
// cheese:    [ {Swiss} Winnie, {Feta} Miriam, {Tilsit} Julie, 
//              {Roquefort} Selena, {Muenster} Rosa, {Edam} Olive]
// crackers:  [ {Cumin_Seed} Olive, {Celery_Seed} Miriam, {Dill_Seed} Rosa, 
//              {Caraway_Seed} Julie, {Poppy_Seed} Selena, {Sesame_Seed} Winnie]
// fruits:    [ {Julie} Apple, {Miriam} Orange, {Olive} Pear, {Rosa} Apple, 
//              {Selena} Pear, {Winnie} Apple]
// beverages: [ {Julie} Tea, {Miriam} Coffee, {Olive} Coffee, {Rosa} Milk, 
//              {Selena} Tea, {Winnie} Coffee]
//
///////////////////////////////////////////////////////////////////////////////                         
//
// Notes: 
//      The query "all CheeseAndCrackers(cheese,cracker,fruit,beverage)" 
//      results in two identical solutions. To avoid displaying both 
//      identical solutions, we collect and display them in the proc 
//      CheeseAndCrackerSolutions.
//
///////////////////////////////////////////////////////////////////////////////                         

// Various type definitions

Woman = Julie | Miriam | Olive | Rosa | Selena | Winnie
Cheese = Swiss | Feta | Tilsit | Roquefort |Muenster | Edam
Cracker = Cumin_Seed | Celery_Seed | Dill_Seed | Caraway_Seed | Poppy_Seed | Sesame_Seed
Fruit = Apple | Orange | Pear
Beverage = Coffee | Milk | Tea

Cheeses = Cheese->>Woman        // Each woman a different cheese
Crackers = Cracker->>Woman      // Each woman a different cracker
Fruits = Woman->Fruit
Beverages = Woman->Beverage

Sequence = [0..5]->>Woman 

///////////////////////////////////////////////////////////////////////////////
//
// Just a simple wrapper for pred CheeseAndCrackers(..)
//
proc CheeseAndCrackerSolutions() iff
    all cheese,cracker,fruit,beverage in l 
        CheeseAndCrackers(cheese,cracker,fruit,beverage)
    end & 
    // Number of distinct solutions is the length of the list of all solutions.
    Print('\nNumber of solutions: ',Len(l),'\n') & PrintSolutions(l)

local proc PrintSolutions(l:<list(ch:Cheeses,cr:Crackers,fr:Fruits,bv:Beverages)) iff
    if l = h,t then
        Print('\ncheese:    ',h.ch) &
        Print('\ncrackers:  ',h.cr) &
        Print('\nfruits:    ',h.fr) &
        Print('\nbeverages: ',h.bv,'\n') & 
        PrintSolutions(t)   // if more then one solution, display them all
    end

///////////////////////////////////////////////////////////////////////////////
//
// The main predicate. Transcribe all clues using F1 syntax.
//
pred CheeseAndCrackers(cheese::Cheeses,cracker::Crackers,fruit::Fruits,bev::Beverages) iff
    sequences :: [0..5]->Sequence &
    sequences = [seq1,seq2,seq3,seq4,seq5,seq6] &

//  At least one person chose each kind of fruit...

    fruit(_) = Apple &
    fruit(_) = Pear &
    fruit(_) = Orange &
    
//  ...and beverage.  

    bev(_) = Tea &
    bev(_) = Milk &
    bev(_) = Coffee &

// 1. The six women are one who ate an apple, the person who sampled the
//    Roquefort cheese, a woman who drank milk, a woman who sipped coffee, 
//    another woman who drank coffee, and a woman who chose tea.
    
    Apple = fruit(apple1) &
    Milk = bev(milk1) &
    Coffee = bev(coffee1a) & 
    Coffee = bev(coffee1b) &
    Tea = bev(tea1) &

    coffee1a <> coffee1b &
    seq1 = [apple1,cheese(Roquefort),milk1,coffee1a,coffee1b,tea1] &

// 2. The six women are a woman who drank tea, a woman who ate a pear, a person 
//    who drank coffee, another woman who ate a pear, the friend who chose the 
//    dill seed crackers, and another woman who sipped coffee.

    Tea = bev(tea2) &
    Coffee = bev(coffee2a) &
    Coffee = bev(coffee2b) &
    Pear = fruit(pear2a) & 
    Pear = fruit(pear2b) & 
    seq2 = [tea2,pear2a,coffee2a,pear2b,cracker(Dill_Seed),coffee2b] &   

// 3. The six women are one who drank coffee, the woman who ate celery seed
//    crackers, the friend who selected the Tilsit cheese, another woman who 
//    drank coffee, a woman who drank tea, and a woman who ate an apple.

    Coffee = bev(coffee3a) &
    Coffee = bev(coffee3b) &
    Tea = bev(tea3) &
    Apple = fruit(apple3)  &
    seq3 = [coffee3a,cracker(Celery_Seed),cheese(Tilsit),coffee3b,tea3,apple3] &

// 4. The six women are one who chose coffee, a friend who ate an apple, a 
//    friend who chose a pear, the one who ate the Muenster cheese, the woman 
//    who ate the caraway seed crackers, and the person who enjoyed the poppy 
//    seed crackers.

    Apple = fruit(apple4) &
    Pear = fruit(pear4) &
    Coffee = bev(coffee4) &
    seq4 = [coffee4,apple4,pear4,cheese(Muenster),cracker(Caraway_Seed),cracker(Poppy_Seed)] &

// 5. The six women are a person who had tea, the woman who ate feta cheese, 
//    a person who had coffee, a woman who had an apple, another woman who had 
//    tea, and another woman who chose an apple.

    Apple = fruit(apple5a) &
    Apple = fruit(apple5b) &
    Coffee = bev(coffee5) &
    Tea = bev(tea5a) &
    Tea = bev(tea5b) &
    seq5 = [tea5a,cheese(Feta),coffee5,apple5a,tea5b,apple5b] &

// 6. The six women are one who ate an apple, the woman who chose the Edam 
//    cheese, a woman who sampled a pear, a woman who sipped coffee, another 
//    woman who had an apple, and the one who selected the sesame seed crackers.

    Apple = fruit(apple6a) &
    Apple = fruit(apple6b) &
    Pear = fruit(pear6) &
    Coffee = bev(coffee6) &
    seq6 = [apple6a,cheese(Edam),pear6,coffee6,apple6b,cracker(Sesame_Seed)] &

// 7. In one of the sequences in clues 1 through 6, the women are listed in the
//    following order: Julie, Miriam, Olive, Rosa, Selena, and Winnie.
    sequences(x1) = [Julie, Miriam, Olive, Rosa, Selena, Winnie] &
    
// 8. In one of the sequences in clues 1 through 6, the women are listed in the
//    following order: Winnie, Selena, Rosa, Olive, Miriam, and Julie.

    sequences(x2) = [Winnie, Selena, Rosa, Olive, Miriam, Julie] &

// 9. In one of the sequences in clues 1 through 6, the women are listed in the 
//    following order: Julie, Olive, Selena, Miriam, Rosa, and Winnie.

    sequences(x3) = [Julie, Olive, Selena, Miriam, Rosa, Winnie] &

//10. In one of the sequences in clues 1 through 6, the women are listed in the 
//    following order: Olive, Miriam, Julie, Winnie, Selena, and Rosa.

    sequences(x4) = [Olive, Miriam, Julie, Winnie, Selena, Rosa] &

//11. In one of the sequences in clues 1 through 6, the women are listed in the 
//    following order: Julie, Olive, Miriam, Selena, Rosa, and Winnie.

    sequences(x5) = [Julie, Olive, Miriam, Selena, Rosa, Winnie] &

//12. In one of the sequences in clues 1 through 6, the women are listed in the 
//    following order: Miriam, Winnie, Olive, Rosa, Julie, and Selena.

    sequences(x6) = [Miriam, Winnie, Olive, Rosa, Julie, Selena]
    



This page was created by F1toHTML