示例#1
0
 def clue_4(self, Students: SuperSequence):
     """ 4. Erma has a $10,000 larger scholarship than Carrie.
     This means that Erma comes after the person who comes after Carrie.
 """
     yield from is_contiguous_in(
         [Student(name='Carrie'),
          Var(), Student(name='Erma')], Students)
示例#2
0
def zebra_problem(Houses):
    for _ in forall([
            # 1. The English live in the red house.
            lambda: member(House(nationality='English', color='red'), Houses),
            # lambda: print_SF(f'After 1: {Houses}', 'Succeed'),

            # 2. The Spanish have a dog.
            lambda: member(House(nationality='Spanish', pet='dog'), Houses),
            # lambda: print_SF(f'After 2: {Houses}', 'Succeed'),

            # 3. They drink coffee in the green house.
            lambda: member(House(drink='coffee', color='green'), Houses),
            # lambda: print_SF(f'After 3: {Houses}', 'Succeed'),

            # 4. The Ukrainians drink tea.
            lambda: member(House(nationality='Ukrainians', drink='tea'), Houses
                           ),
            # lambda: print_SF(f'After 4: {Houses}', 'Succeed'),

            # 5. The green house is immediately to the right of the white house.
            lambda: is_contiguous_in(
                [House(color='white'),
                 House(color='green')], Houses),
            # lambda: print_SF(f'After 5: {Houses}', 'Succeed'),

            # 6. The Old Gold smokers have snails.
            lambda: member(House(smoke='Old Gold', pet='snails'), Houses),
            # lambda: print_SF(f'After 6: {Houses}', 'Succeed'),

            # 7. They smoke Kool in the yellow house.
            lambda: member(House(smoke='Kool', color='yellow'), Houses),
            # lambda: print_SF(f'After 7: {Houses}', 'Succeed'),

            # 8. They drink milk in the middle house.
            # Note the use of a slice. Houses[2] picks the middle house.
            lambda: unify(House(drink='milk'), Houses[2]),
            # lambda: print_SF(f'After 8: {Houses}', 'Succeed'),

            # 9. The Norwegians live in the first house on the left.
            lambda: unify(House(nationality='Norwegians'), Houses.head()),
            # lambda: print_SF(f'After 9: {Houses}', 'Succeed'),

            # 10. The Chesterfield smokers live next to the fox.
            lambda: next_to(House(smoke='Chesterfield'), House(pet='fox'),
                            Houses),
            # lambda: print_SF(f'After 10: {Houses}', 'Succeed'),

            # 11. They smoke Kool in the house next to the horse.
            lambda: next_to(House(smoke='Kool'), House(pet='horse'), Houses),
            # lambda: print_SF(f'After 11: {Houses}', 'Succeed'),

            # 12. The Lucky smokers drink juice.
            lambda: member(House(drink='juice', smoke='Lucky'), Houses),
            # lambda: print_SF(f'After 12: {Houses}', 'Succeed'),

            # 13. The Japanese smoke Parliament.
            lambda: member(House(nationality='Japanese', smoke='Parliament'),
                           Houses),
            # lambda: print_SF(f'After 13: {Houses}', 'Succeed'),

            # 14. The Norwegians live next to the blue house.
            lambda: next_to(House(nationality='Norwegians'), House(color='blue'
                                                                   ), Houses),
            # lambda: print_SF(f'After 14: {Houses}', 'Succeed'),

            # Fill in unmentioned properties.
            lambda: members([House(pet='zebra'),
                             House(drink='water')], Houses),
    ]):
        yield
示例#3
0
 def clue_4(self, Stdnts):
     """ Marie has a $10,000 larger scholarship than
     Lynn. """
     yield from is_contiguous_in(
         [Stdnt(name='Lynn'),
          Var(), Stdnt(name='Marie')], Stdnts)
示例#4
0
 def clue_3(self, Stdnts):
     """ The Stdnt who studies CS has a
     $5,000 larger scholarship than Lynn. """
     yield from is_contiguous_in(
         [Stdnt(name='Lynn'), Stdnt(major='CS')], Stdnts)
示例#5
0
 def clue_5(self, Houses: SuperSequence):
     """ 5. The green house is immediately to the right of the white house. """
     yield from is_contiguous_in(
         [House(color='white'), House(color='green')], Houses)
示例#6
0
 def clue_3(self, Students: SuperSequence):
     """ 3. The student who studies Comp Sci has a $5,000 larger scholarship than Carrie. """
     # To avoid arithmetic, take advantage of the known structure of the Scholarships list.
     yield from is_contiguous_in(
         [Student(name='Carrie'),
          Student(major='Comp Sci')], Students)