Courses/CS 460/Fall 2005/Homework/Jeff Bailey/Oct 22

From CSWiki

Jump to: navigation, search

Contents


Only got 1 of 3 working correctly so far. The other two are very close returning a handful of possible solutions

[edit] Geography Assignments

Demonstrated in class 10.22.2005

Mrs. Magoo’s sixth-grade class was divided into different teams, and each team was given their Geography assignments. One team of four children, including Adam, were to write on a natural wonder of the world. Each chose to write on a natural wonder found on a different continent. From the clues, determine each child’s first name, the natural wonder each chose to write about (one is volcanos), and the continent on which each natural wonder was located.

  • Bethany didn’t write about a natural wonder found in North America.
  • The natural wonder Denise chose to write a report on (which was not caves) was one found on the continent of Africa.
  • The subject of the report given by Curtis wasn’t caves or waterfalls (which was the subject of the student who chose the continent of Europe.
  • One student selected to write about a natural wonder found in Asia, but it was neither about caves or hot springs.
local
   Name = [adam bethany curtis denise]
   Wonder = [caves hotsprings volcanos waterfalls]
   Continent = [africa america asia europe]

   % procs provided in class
   proc {Append ?Xs ?Ys ?Zs}
      choice
         Xs = nil
 	 Ys = Zs
      [] Head XRest ZRest in
	 Xs = Head|XRest 
	 Zs = Head|ZRest
	 {Append XRest Ys ZRest}
      end
   end
  
   proc {IsAPropertyValue SPs ?Property ?Value}
      {IsAMember Property#Value {Record.toListInd SPs}}
   end

   proc {IsAMember ?X Xs} {Append _ X|_ Xs} end

   proc {IsAName ?X} {IsAMember X Name} end
   proc {IsAWonder ?X} {IsAMember X Wonder} end
   proc {IsAContinent ?X} {IsAMember X Continent} end
   
   % clues

   % Bethany didnt write about a natural wonder found in America.
   proc {Clue1 Xs}
      C1 N1
   in
      {IsAPropertyValue Xs C1 bethany}
      {IsAContinent C1}
      C1 == america = false

      {IsAPropertyValue Xs america N1}
      {IsAName N1}
      N1 == bethany = false
   end

   % The natural wonder Denise chose to write a report on (which was
   % not caves) was one found ion the continent of Africa
   proc {Clue2 Xs}
      C1 C2 C3 N1 W1 
   in
      % denise reported on wonder in africa
      {IsAPropertyValue Xs africa denise}

      % so nobody else can
      {IsAPropertyValue Xs C1 adam}
      {IsAPropertyValue Xs C2 bethany}
      {IsAPropertyValue Xs C3 curtis}
      {IsAContinent C1}
      {IsAContinent C2}
      {IsAContinent C3}
      C1 == africa = false
      C2 == africa = false
      C3 == africa = false

      % and it wasnt on caves
      {IsAPropertyValue Xs W1 denise}
      {IsAWonder W1}
      W1 == caves = false

      % someone else must have done that
      {IsAPropertyValue Xs caves N1}
      {IsAName N1}
      N1 == denise = false
   end

   % The subject of the report given by Curtis wasnt caves or waterfalls
   % (which was the subject of the student who chose the continent of
   % Europe).
   proc {Clue3 Xs}
      C1 C2 N1 N2 W1
   in
      % curtis did neither caves not waterfalls
      {IsAPropertyValue Xs W1 curtis}
      {IsAWonder W1}
      W1 == caves = false
      W1 == waterfalls = false

      % curtis didnt do europe
      {IsAPropertyValue Xs C1 curtis}
      {IsAContinent C1}
      C1 == europe = false

      % whoever did europe did waterfalls
      {IsAPropertyValue Xs europe N1}
      {IsAName N1}
      {IsAPropertyValue Xs waterfalls N1}
      N1 == curtis = false

      % and someone did caves
      {IsAPropertyValue Xs caves N2}
      {IsAName N2}
      N2 == curtis = false

      % which are not in europe
      {IsAPropertyValue Xs C2 N2}
      {IsAContinent C2}
      C2 == europe = false
   end

   % One student selected to write about a natural wonder found in Asia,
   % but it was neither about caves or hot springs
   proc {Clue4 Xs}
      C1 N1 W1
   in
      % whoever picked asia
      {IsAPropertyValue Xs asia N1}
      {IsAName N1}

      % did neither caves nor hotsprings
      {IsAPropertyValue Xs W1 N1}
      {IsAWonder W1}
      W1 == caves = false
      W1 == hotsprings = false
   end
   
   fun {Geography}
      Properties = {FoldR [Wonder Continent] Append nil}
      Assignments = {MakeRecord assignments Properties}
   in
      {Clue1 Assignments}
      {Clue2 Assignments}
      {Clue3 Assignments}
      {Clue4 Assignments}
      
      Assignments
   end
in
   {Browse {SearchAll Geography}}
end

[edit] New Years Birthdays

The five Morgan children were all born on January 1st, New Years’s Day, two years apart (ages 8, 10, 12, 14, and 16). This year for their birthdays, each received a different gift from their parents. From the clues, determine each child’s name, age, and the gift he or she received for a birthday present.

  • Kristol is younger than the child who received the banjo, who is not the oldest of the five children.
  • Jason is not the child who received a Nintendo game for his or her birthday gift (who is older than Brent).
  • The girl who received the bicycle is younger than Brent, who isn’t the child who received the telescope.
  • Teddy, who didn’t receive the digital camera, is older than the child who received the telescope, who in turn is older than Amy.
  • It was not the oldest child who received the Nintendo game.
local
   Name = [amy brent jason kristol teddy]
   Age = [8 10 12 14 16]
   Gift = [banjo bicycle camera nintendo telescope]

   % procs provided in class
   proc {Append ?Xs ?Ys ?Zs}
      choice
         Xs = nil
 	 Ys = Zs
      [] Head XRest ZRest in
	 Xs = Head|XRest 
	 Zs = Head|ZRest
	 {Append XRest Ys ZRest}
      end
   end
  
   proc {IsAPropertyValue SPs ?Property ?Value}
      {IsAMember Property#Value {Record.toListInd SPs}}
   end

   proc {IsAMember ?X Xs} {Append _ X|_ Xs} end

   proc {IsAName ?X} {IsAMember X Name} end
   proc {IsAnAge ?X} {IsAMember X Age} end
   proc {IsAGift ?X} {IsAMember X Gift} end

   % uniqueness constraints (guarantee values for all properties)
   proc {UniqueAges Xs}
      N1 N2 N3 N4 N5
   in
      {IsAPropertyValue Xs 8 N1}
      {IsAPropertyValue Xs 10 N2}
      {IsAPropertyValue Xs 12 N3}
      {IsAPropertyValue Xs 14 N4}
      {IsAPropertyValue Xs 16 N5}

      {IsAName N1}
      {IsAName N2}
      {IsAName N3}
      {IsAName N4}
      {IsAName N5}

      N1 == N2 = false
      N1 == N3 = false
      N1 == N4 = false
      N1 == N5 = false
      N2 == N3 = false
      N2 == N4 = false
      N2 == N5 = false
      N3 == N4 = false
      N3 == N5 = false
      N4 == N5 = false
   end

   proc {UniqueGifts Xs}
      N1 N2 N3 N4 N5
   in
      {IsAPropertyValue Xs banjo N1}
      {IsAPropertyValue Xs bicycle N2}
      {IsAPropertyValue Xs camera N3}
      {IsAPropertyValue Xs nintendo N4}
      {IsAPropertyValue Xs telescope N5}

      {IsAName N1}
      {IsAName N2}
      {IsAName N3}
      {IsAName N4}
      {IsAName N5}

      N1 == N2 = false
      N1 == N3 = false
      N1 == N4 = false
      N1 == N5 = false
      N2 == N3 = false
      N2 == N4 = false
      N2 == N5 = false
      N3 == N4 = false
      N3 == N5 = false
      N4 == N5 = false
   end

% clues

   % Kristol is younger than the child who received the banjo, who is
   % not the oldest of the five children.
   proc {Clue1 Xs}
      A1 A2 G1 N1
   in
      % kristol not oldest or second oldest
      {IsAPropertyValue Xs A1 kristol}
      {IsAnAge A1}
      A1 == 16 = false
      A1 == 14 = false

      % kristol didnt receive banjo
      {IsAPropertyValue Xs G1 kristol}
      {IsAGift G1}
      G1 == banjo = false

      % person who received banjo is not oldest, second oldest or youngest
      {IsAPropertyValue Xs banjo N1}
      {IsAName N1}
      {IsAPropertyValue Xs A2 N1}
      {IsAnAge A2}
      A2 == 8 = false
      A2 == 14 = false
      A2 == 16 = false
   end

   % Jason is not the child who received a Nintendo game for his or her
   % birthday gift (who is older than Brent)
   proc {Clue2 Xs}
      G1 A1 A2 N1
   in
      % jason didnt get nintendo
      {IsAPropertyValue Xs G1 jason}
      {IsAGift G1}
      G1 == nintendo = false

      % brent isnt oldest
      {IsAPropertyValue Xs A1 brent}
      {IsAnAge A1}
      A1 == 16 = false

      % nintendo recipient is not youngest
      {IsAPropertyValue Xs nintendo N1}
      {IsAName N1}
      {IsAPropertyValue Xs A2 N1}
      {IsAnAge A2}
      A2 == 8 = false
   end
   
   % The girl who received the bicycle is younger than Brent, who isnt
   % the child who received the telescope.
   proc {Clue3 Xs}
      N1 A1 A2 N2
   in
      % girl who received bike
      {IsAPropertyValue Xs bicycle N1}
      {IsAName N1}
      N1 == brent = false
      N1 == jason = false
      N1 == teddy = false

      % is not oldest
      {IsAPropertyValue Xs A1 N1}
      {IsAnAge A1}
      A1 == 16 = false

      % brent isnt youngest
      {IsAPropertyValue Xs A2 brent}
      {IsAnAge A2}
      A2 == 8 = false

      % brent didnt receive telescope
      {IsAPropertyValue Xs telescope N2}
      {IsAName N2}
      N2 == brent = false
   end

   % Teddy, who didnt receive the digital camera, is older than
   % the child who received the telescope, who in turn is older
   % than Amy.   
   proc {Clue4 Xs}
      G1 G2 N1 N2 A1 A2 A3
   in
      % neither teddy nor amy got camera or telescope
      {IsAPropertyValue Xs G1 teddy}
      {IsAGift G1}
      G1 == camera = false
      G1 == telescope = false

      {IsAPropertyValue Xs G2 amy}
      {IsAGift G2}
      G2 == camera = false
      G2 == camera = false
  
      % teddy not youngest or second youngest
      {IsAPropertyValue Xs A1 teddy}
      {IsAnAge A1}
      A1 == 8 = false
      A1 == 10 = false

      % child who received telescope is not youngest or oldest
      {IsAPropertyValue Xs telescope N2}
      {IsAName N2}
      {IsAPropertyValue Xs A2 N2}
      {IsAnAge A2}
      A2 == 8 = false
      A2 == 16 = false

      % amy is not oldest or second oldest
      {IsAPropertyValue Xs A3 amy}
      {IsAnAge A3}
      A3 == 16 = false
      A3 == 14 = false
   end

   % It was not the oldest child who received the Nintendo game.
   proc {Clue5 Xs}
      N1 A1
   in
      {IsAPropertyValue Xs nintendo N1}
      {IsAName N1}
      {IsAPropertyValue Xs A1 N1}
      {IsAnAge A1}
      A1 == 16 = false
   end   
   
   fun {Birthday}
      Properties = {FoldR [Age Gift] Append nil}
      Birthdays = {MakeRecord birthdays Properties}
   in
      {UniqueAges Birthdays}
      {UniqueGifts Birthdays}
      
      {Clue1 Birthdays}
      {Clue2 Birthdays}
      {Clue3 Birthdays}
      {Clue4 Birthdays}
      {Clue5 Birthdays}
      Birthdays
   end
in
   {Browse {SearchAll Birthday}}
end


[edit] Marjie's Candle & Bath

Recently, a new store opened at the Mall called Marjie’s Candle & Bath. On opening day, the first four customers entered at 8:00 AM exactly and each purchased a different item. Marjie makes all her own candles, scented bath oils, body lotion, and bath soap. Each customer, one of whom is Connie, purchased an item in one of four scents - Jasmine, Lavender, Mulberry, or Rosemary. From the clues determine the scented item each woman purchased

  • The four women are Greta, Polly, the woman who purchased the candles, and the woman who purchased the Mulberry scented item.
  • Polly isn’t the woman who purchased an item scented with Rosemary, nor were the candles purchased by one woman Rosemary scented.
  • Kristine, the woman who purchased a Lavender scented item, and the woman who purchased a Mulberry scented item planned on doing more shopping after leaving Marjie’s Candle & Bath while this was the last stop on the fourth woman’s list.
  • The woman who purchased an item that was Lavender scented didn’t purchase any body lotion.
  • Greta is neither the woman who purchased some body lotion nor the woman who purchased some scented bath oil.


local
   Name = [connie greta kristine polly]
   Item = [candle lotion oil soap]
   Scent = [jasmine lavender mulberry rosemary]
   
   % procs provided in class
   proc {Append ?Xs ?Ys ?Zs}
      choice
         Xs = nil
 	 Ys = Zs
      [] Head XRest ZRest in
	 Xs = Head|XRest 
	 Zs = Head|ZRest
	 {Append XRest Ys ZRest}
      end
   end
  
   proc {IsAPropertyValue SPs ?Property ?Value}
      {IsAMember Property#Value {Record.toListInd SPs}}
   end

   proc {IsAMember ?X Xs} {Append _ X|_ Xs} end

   proc {IsAName ?X} {IsAMember X Name} end
   proc {IsAnItem ?X} {IsAMember X Item} end
   proc {IsAScent ?X} {IsAMember X Scent} end

% clues

   % The four women are Greta, Polly, the woman who purchased the candles,
   % and the woman who purchased the Mulberry scented item.
   proc {Clue1 Xs}
      N1 N2
   in
      {IsAPropertyValue Xs candle N1}
      {IsAName N1}
      N1 == greta = false
      N1 == polly = false

      {IsAPropertyValue Xs mulberry N2}
      {IsAName N2}
      N2 == greta = false
      N2 == polly = false
      N1 == N2 = false 
   end

   % Polly isnt the woman who purchased an item scented with Rosemary, nor
   % were the candles purchased by one woman Rosemary scented.
   proc {Clue2 Xs}
      N1 N2
   in
      {IsAPropertyValue Xs rosemary N1}
      {IsAName N1}
      N1 == polly = false

      {IsAPropertyValue Xs candle N2}
      {IsAName N2}
      N2 == N1 = false     
   end

   % Kristine, the woman who purchased a Lavender scented item, and the woman
   % who purchased a Mulberry scented item planned on doing more shopping after
   % leaving Marjies Candle & Bath while this was the last stop on the fourth
   % womans list.
   proc {Clue3 Xs}
      N1 N2
   in
      {IsAPropertyValue Xs lavender N1}
      {IsAName N1}
      N1 == kristine = false

      {IsAPropertyValue Xs mulberry N2}
      {IsAName N2}
      N1 == kristine = false
      N1 == N2 = false
   end

   % Greta is neither the woman who purchased some body lotion nor the woman who
   % purchased some scented bath oil
   proc {Clue4 Xs}
      I1
   in
      {IsAPropertyValue Xs I1 greta}
      {IsAnItem I1}
      I1 == lotion = false
      I1 == oil = false
   end

   fun {Shoppers}
      Properties = {FoldR [Scent Item] Append nil}
      Shoppers  = {MakeRecord shoppers Properties}
   in
      {Clue1 Shoppers}
      {Clue2 Shoppers}
      {Clue3 Shoppers}
      {Clue4 Shoppers}

      Shoppers
   end
in
   {Browse {SearchAll Shoppers}}
end