Jump to content

Zebra puzzle: Difference between revisions

m
(Added Wren)
Line 2,587:
=={{header|FormulaOne}}==
<lang FormulaOne>
// First, let's give some type-variables some values:
Nationality = Englishman | Swede | Dane | Norwegian | German
Colour = Red | Green | Yellow | Blue | White
Line 2,598:
We use injections to make the array-elements unique.
Example: 'Pet' is an array of unique elements of type 'Domestic', indexed by 'Nationality'.
In the predicate 'Zebra', we use this injection 'Pet' to define the array-variable 'pet' as a parameter if the 'Zebra'-predicate.
The symbol used is the '->>'. 'Nationality->>Domestic' can be read as 'Domestic(Nationality)' in "plain array-speak";
the difference being that the elements are by definition unique (cf. 'injective function').
So, in FormulaOne we use a formula like: 'pet(Swede) = Dog', which simply means that the 'Swede' (type 'Nationality')
has a 'pet' (type 'Pet', which is of type 'Domestic', indexed by 'Nationality'), which appears to be a 'Dog' (type 'Domestic').
Or, one could say that the 'Swede' has been mapped to the 'Dog' (Oh, well...).
}
Line 2,643:
{ 5. The green house is immediately to the left of the white house: }
{ The local predicate 'LeftOf' (see below) determines the order: }
LeftOf(green_house, white_house, order) &
Line 2,655:
smoke(yellow_house) = Dunhill &
{ 9. In the middle house (third in the row) they drink milk: }
drink(order(Third)) = Milk &
Line 2,674:
smoke(German) = Prince &
{15. The Norwegian lives next to the blue house: }
{Cf. 10. "The Norwegian lives in the first house", so the blue house is the second house: }
houseColour(order(Second)) = Blue &
so the blue house is the second house }
houseColour(order(Second)) = Blue &
{16. They drink water in a house next to the house where they smoke Blend: }
Line 2,735 ⟶ 2,734:
pet(cat_keeper) = Cat &
pet(neighbour_dunhill_smoker) = Horse &
 
houseColour(Englishman) = Red &
pet(Swede) = Dog &
Line 2,765 ⟶ 2,763:
{{out}}
<pre>
houseColour = [ {Englishman} Red, {Swede} White, {Dane} Blue, {Norwegian} Yellow, {German} Green ]
pet = =[ {Englishman} Birds, {Swede} Dog, {Dane} Horse, {Norwegian} Cats, {German} Zebra ]
smokes = =[ {Englishman} PallMall, {Swede} BlueMaster, {Dane} Blend, {Norwegian} Dunhill, {German} Prince ]
drinks = =[ {Englishman} Milk, {Swede} Beer, {Dane} Tea, {Norwegian} Water, {German} Coffee ]
order = =[ {First} Norwegian, {Second} Dane, {Third} Englishman, {Fourth} German, {Fifth}, Swede ]
</pre>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.