Exemplo n.º 1
0
 def clue_14(self, Houses: SuperSequence):
     """ 14. The Norwegians live next to the blue house. """
     for _ in next_to(House(nationality='Norwegians'), House(color='blue'),
                      Houses):
         yield from self.clue_15(Houses)
Exemplo n.º 2
0
 def clue_10(self, Houses: SuperSequence):
     """ 10. The Chesterfield smokers live next to the fox.
     Saying 'next to' doesn't commit to the right or left. """
     for _ in next_to(House(smoke='Chesterfield'), House(pet='fox'),
                      Houses):
         yield from self.clue_11(Houses)
Exemplo n.º 3
0
 def clue_11(self, Houses: SuperSequence):
     """ 11. They smoke Kool in the house next to the horse. """
     for _ in next_to(House(smoke='Kool'), House(pet='horse'), Houses):
         yield from self.clue_12(Houses)
Exemplo n.º 4
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