Courses/CS 460/Fall 2005/Homework/Joey Leung/Oct 22

From CSWiki

Jump to: navigation, search

Contents

[edit] Solve 3 Puzzles

[edit] Flower Boxes

Mary and three other women had flower boxes in windows on either side of their front doors and each woman planted a different type of flower in her window flower boxes (one woman planted petunias). From the clues, can you determine the first name and last name (one is Gumble) of each woman and the type of flower each woman planted?


1. The four women - Julie, Ms. Drake, Ms. Evans, and the woman who planted daisies, all belong to the same gardening club.

2. The woman who planted violets in her flower boxes isn’t Kate.

3. Ms. Drake isn’t the woman who planted marigolds.

4. Ms. Florez, who didn’t plant violets, is married to Lola’s brother.

5. Marigolds were not the flower of choice for Julie.

6. Kate, whose surname isn’t Evans, didn’t plant daisies in her window flower boxes.


[edit] Take 1

For the result display in which I chose FirstName and Flowers. I am already stuck on Clue 1, I do not how to implement it.


local

   FirstNames = [mary julie kate lola]
   LastNames = [drake evans florez gumble]
   Flowers = [petunias daisies marigolds violets]
   
   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 {IsAFirstName ?FirstName} {IsAMember FirstName FirstNames} end
   proc {IsALastName ?LastName} {IsAMember LastName LastNames} end
   proc {IsAFlower ?Flower} {IsAMember Flower Flowers} end

   proc {Clue1 SPs} 
      P1 P2 in
      {IsAPropertyValue SPs P1 evans}
      P1 == daisies = false
      P1 == julie = false
       {IsAPropertyValue SPs P2 drake}
      P2 == daisies = false
      P2 == julie = false
   end

   proc {Clue2 SPs} 
      SPs.violets  == kate = false
   end

   proc {Clue3 SPs} 
      P1 in
      {IsAPropertyValue SPs P1 drake}
      P1 == marigolds = false
   end

   proc {Clue4 SPs}
      P1 in
      {IsAPropertyValue SPs P1 florez}
      P1 == violets = false
      P1 == lola = false
   end

   proc {Clue5 SPs} 
      SPs.marigolds == julie = false
   end

   proc {Clue6 SPs}
      SPs.evans == kate = false
      SPs.daisies == kate =false
   end
   
   fun {FlowerBoxes}
      Properties = {FoldR [FirstNames Flowers] Append nil}
      SPs = {MakeRecord flowerboxesProperties Properties}
   in
      {Clue1 SPs}
      {Clue2 SPs}
      {Clue3 SPs}
      {Clue4 SPs}
      {Clue5 SPs}
      {Clue6 SPs}
      SPs
   end
in
   {Browse {SearchAll FlowerBoxes}}
end


[edit] Take 2


local

   FirstNames = [mary julie kate lola]
   LastNames = [drake evans florez gumble]
   Flowers = [petunias daisies marigolds violets]
   
   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 {IsAFirstName ?FirstName} {IsAMember FirstName FirstNames} end
   proc {IsALastName ?LastName} {IsAMember LastName LastNames} end
   proc {IsAFlower ?Flower} {IsAMember Flower Flowers} end

   proc {Clue1 SPs} 
      P1 P2 P3 P4 in
      {IsAPropertyValue SPs P1 evans}
      {IsAPropertyValue SPs P2 drake}
      {IsAPropertyValue SPs daisies P3}
      {IsAPropertyValue SPs julie P4}
      {IsALastName P3}
      {IsALastName P4}
      P1 == daisies = false
      P1 == julie = false
      P2 == daisies = false
      P2 == julie = false
      P3 == drake = false
      P3 == evans = false
      P4 == drake = false
      P4 == evans = false
      P3 == P4 = false
      P1 == P3 = false
      P1 == P4 = false
   end

   proc {Clue2 SPs}
      P1 in
      {IsAPropertyValue SPs kate P1}
      {IsALastName P1}
      SPs.violets == P1 = false
   end

   proc {Clue3 SPs} 
      P1 in
      {IsAPropertyValue SPs P1 drake}
      P1 == marigolds = false
   end

   proc {Clue4 SPs}
      P1 in
      {IsAPropertyValue SPs P1 florez}
      P1 == violets = false
      P1 == lola = false
   end

   proc {Clue5 SPs} 
      P1 in
      {IsAPropertyValue SPs julie P1}
      {IsALastName P1}
      SPs.marigolds == P1 = false
   end

   proc {Clue6 SPs}
      P1 P2 in
      {IsAPropertyValue SPs kate P1}
      {IsALastName P1}
      P1 == evans = false
      SPs.dasies == P1 = false
   end
   
   fun {FlowerBoxes}
      Properties = {FoldR [FirstNames Flowers] Append nil}
      SPs = {MakeRecord flowerboxesProperties Properties}
   in
      %{Clue1 SPs}
      %{Clue2 SPs}
      %{Clue3 SPs}
      %{Clue4 SPs}
      %{Clue5 SPs}
      {Clue6 SPs}
      SPs
   end
in
   {Browse {SearchAll FlowerBoxes}}
end


[edit] Take 3

Got closer to the problem, however couldn't figure out why clue 4 is not working.


local

   FirstNames = [mary julie kate lola]
   LastNames = [drake evans florez gumble]
   Flowers = [petunias daisies marigolds violets]
   
   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 {IsAFirstName ?FirstName} {IsAMember FirstName FirstNames} end
   proc {IsALastName ?LastName} {IsAMember LastName LastNames} end
   proc {IsAFlower ?Flower} {IsAMember Flower Flowers} end

   % Evan, Drake, Julie, and the woman who planted daisies are 4 different people.
   proc {Clue1 SPs} 
      P1 P2 P3 P4 in
      {IsAPropertyValue SPs evans P1}
      {IsAPropertyValue SPs drake P2}
      {IsAPropertyValue SPs julie P3}
      {IsAFlower P1}
      {IsAFlower P2}
      {IsAFlower P3}
      P1 == daisies = false
      P2 == daisies = false
      P3 == daisies = false
      P1 == P2 = false
      P1 == P3 = false
      P2 == P3 = false
   end

   % Kate did not plant violets
   proc {Clue2 SPs}
      P1 in
      {IsAPropertyValue SPs kate P1}
      {IsAFlower P1}
      P1 == violets = false
   end

   %Drake did not plant marigolds
   proc {Clue3 SPs} 
      P1 in
      {IsAPropertyValue SPs drake P1}
      {IsAFlower P1}
      P1 == marigolds = false
   end

   % Florez did not plant violet and is not Lola
   proc {Clue4 SPs}
      P1 in
      {IsAPropertyValue SPs florez P1}
      {IsAFlower P1}
      P1 == violets = false
      P1 == SPs.lola = false
   end

   %Julie did not plant marigolds
   proc {Clue5 SPs} 
      P1 in
      {IsAPropertyValue SPs julie P1}
      {IsAFlower P1}
      P1 == marigolds = false
   end

   %Kate did not plant daisies and is not Evans
   proc {Clue6 SPs}
      P1 P2 in
      {IsAPropertyValue SPs kate P1}
      {IsAFlower P1}
      P1 == daisies = false
      P1 == SPs.evans = false
   end
   
   proc {Remain SPs}
      P1 P2 in
      {IsAPropertyValue SPs gumble P1}
      {IsAFlower P1}
      P1 == SPs.drake = false
      P1 == SPs.evans = false
      P1 == SPs.florez = false
      {IsAPropertyValue SPs petunias P2}
      {IsAFlower P2}
      P2 == SPs.daisies = false
      P2 == SPs.marigolds = false
      P2 == SPs.violets = false
   end

   fun {FlowerBoxes}
      Properties = {FoldR [FirstNames LastNames] Append nil}
      SPs = {MakeRecord flowerboxesProperties Properties}
   in
      {Clue1 SPs}
      {Clue2 SPs}
      {Clue3 SPs}
      %{Clue4 SPs}
      %{Clue5 SPs}
      %{Clue6 SPs}
      %{reamin SPs}
      SPs
   end
in
   {Browse {SearchAll FlowerBoxes}}
end


[edit] Arbor Day Planting

Each of four men who live in Willowbrook Estates on the city’s north side, planted a different type of tree in their front yard on Arbor Day. From The clues, determine the first and last name of each man and the type of tree each planted.

1. George, Mr.Clary, and Mr. Becker (who got his tree from HomeTown Garden Center) all live within three blocks of one another.

2. Mr. Clary planted neither the cedar tree or the maple tree.

3. Harvey and Mr. Clary live next door to one another.

4. The ash tree was not planted by neither John nor Ivan.

5. The maple tree was not the tree planted by George (who is not surnamed Delgado).

6. Mr. Erichsen isn’t the man who planted the ash tree.

7. John, who purchased his tree at the Green Thumb Greenhouse, isn’t the man who planted the sycamore.


[edit] Take 1


local

   Trees = [ash cedar maple sycamore]
   FirstNames = [george harvey ivan john]
   LastNames = [becker clary delgado erichsen]
   
   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 {IsAFirstName ?FirstName} {IsAMember FirstName FirstNames} end
   proc {IsALastName ?LastName} {IsAMember LastName LastNames} end
   proc {IsATree ?Tree} {IsAMember Tree Trees} end

  proc {Clue1 SPs}
      T1 T2 T3 in
      {IsAPropertyValue SPs clary T1}
      {IsATree T1}
      {IsAPropertyValue SPs becker T2}
      {IsATree T2}
      {IsAPropertyValue SPs george T3}
      {IsATree T3}
      T1 == T2 = false
      T1 == T3 = false
      T2 == T3 = false
   end
   
   proc {Clue2 SPs}
      T1 in
      {IsAPropertyValue SPs clary T1}
      {IsATree T1}
      T1 == ash = false
      T1 == sycamore = false
   end
   
   proc {Clue3 SPs}
      SPs.clary == harvey = false
   end
   
   proc {Clue4 SPs}
      P1 in
      {IsAPropertyValue SPs P1 ash}
      {IsAFirstName P1}
      P1 == john = false
      P1 == ivan = false
    end
   
   proc {Clue5 SPs}
      T1 in
      {IsAPropertyValue SPs george T1}
      {IsATree T1}
      T1 == maple = false
      SPs.delgado == george = false
   end

   proc {Clue6 SPs}
      T1 in
      {IsAPropertyValue SPs erichsen T1}
      {IsATree T1}
      T1 == ash = false
    end

   proc {Clue7 SPs}
      SPs.becker == john = false
      T1 T2 in
      {IsAPropertyValue SPs john T1}
      {IsATree T1}
      T1 == sycamore = false
    end
           
   fun {ArborDayPlanting}
      Properties = {FoldR [FirstNames LastNames] Append nil}
      SPs = {MakeRecord plantingProperties Properties}
      T1 T2
   in
      {Clue1 SPs}
      {Clue2 SPs}
      {Clue3 SPs}
      {Clue4 SPs}
      {Clue5 SPs}
      {Clue6 SPs}
      {Clue7 SPs} 
      SPs
   end
in
   {Browse {SearchAll ArborDayPlanting }}
end



[edit] Take 2

Still does not work.


local

   Trees = [ash cedar maple sycamore]
   FirstNames = [george harvey ivan john]
   LastNames = [becker clary delgado erichsen]
   
   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 {IsAFirstName ?FirstName} {IsAMember FirstName FirstNames} end
   proc {IsALastName ?LastName} {IsAMember LastName LastNames} end
   proc {IsATree ?Tree} {IsAMember Tree Trees} end

   % George, Mr.Clary, and Mr. Becker are different person
   proc {Clue1 SPs}
      L1 in
      {IsAPropertyValue SPs george L1}
      {IsALastName L1}
      L1 == clary = false
      L1 == becker = false
   end
   
   % Mr. Clary planted cedar tree or the maple tree
   proc {Clue2 SPs}
      L1 L2 in
      {IsAPropertyValue SPs cedar L1}
      {IsALastName L1}
      L1 == clay = false
      {IsAPropertyValue SPs maple L2}
      {IsALastName L2}
      L2 == clay = false
      L1 == L2 = false
   end
   
   % Harvey and Mr. Clary are different person
   proc {Clue3 SPs}
      L1 in
      {IsAPropertyValue SPs harvey L1}
      {IsALastName L1}
      L1 == clary = false
   end
   
   % ash tree was not planted by John nor Ivan
   proc {Clue4 SPs}
      SPs.ash == SPs.john = false
      SPs.ash == SPs.ivan = false
   end
   
   % George is not Delgado and did not plant maple tree
   proc {Clue5 SPs}
      L1 in
      {IsAPropertyValue SPs george L1}
      {IsALastName L1}
      L1 == delgado = false
      SPs.maple == delgado = false
   end

   % Mr. Erichsen did not plant ash tree
   proc {Clue6 SPs}
      L1 in
      {IsAPropertyValue SPs ash L1}
      {IsALastName L1}
      L1 == erichsen = false
   end

   % John did not plant sycamore
   proc {Clue7 SPs}
      SPs.sycamore == SPs.john = false    
    end
           
   fun {ArborDayPlanting}
      Properties = {FoldR [FirstNames Trees] Append nil}
      SPs = {MakeRecord plantingProperties Properties}
      L1 L2
   in
      {Clue1 SPs}
      {Clue2 SPs}
      {Clue3 SPs}
      {Clue4 SPs}
      {Clue5 SPs}
      {Clue6 SPs}
      {Clue7 SPs} 
      SPs
   end
in
   {Browse {SearchAll ArborDayPlanting }}
end