Zebra puzzle: Difference between revisions

Content deleted Content added
PureFox (talk | contribs)
Added Wren
Line 2,587: Line 2,587:
=={{header|FormulaOne}}==
=={{header|FormulaOne}}==
<lang FormulaOne>
<lang FormulaOne>
// First, let's give some variables some values:
// First, let's give some type-variables some values:
Nationality = Englishman | Swede | Dane | Norwegian | German
Nationality = Englishman | Swede | Dane | Norwegian | German
Colour = Red | Green | Yellow | Blue | White
Colour = Red | Green | Yellow | Blue | White
Line 2,598: Line 2,598:
We use injections to make the array-elements unique.
We use injections to make the array-elements unique.
Example: 'Pet' is an array of unique elements of type 'Domestic', indexed by 'Nationality'.
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'.
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 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.
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')
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').
has a 'pet' (type 'Pet', 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...).
Or, one could say that the 'Swede' has been mapped to the 'Dog' (Oh, well...).
}
}
Line 2,643: Line 2,643:
{ 5. The green house is immediately to the left of the white house: }
{ 5. The green house is immediately to the left of the white house: }
{ The local predicate 'LeftOf' determines the order: }
{ The local predicate 'LeftOf' (see below) determines the order: }
LeftOf(green_house, white_house, order) &
LeftOf(green_house, white_house, order) &
Line 2,655: Line 2,655:
smoke(yellow_house) = Dunhill &
smoke(yellow_house) = Dunhill &
{ 9. In the middle house they drink milk: }
{ 9. In the middle house (third in the row) they drink milk: }
drink(order(Third)) = Milk &
drink(order(Third)) = Milk &
Line 2,674: Line 2,674:
smoke(German) = Prince &
smoke(German) = Prince &
{15. The Norwegian lives next to the blue house: }
{15. The Norwegian lives next to the blue house
{10. The Norwegian lives in the first 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: }
{16. They drink water in a house next to the house where they smoke Blend: }
Line 2,735: Line 2,734:
pet(cat_keeper) = Cat &
pet(cat_keeper) = Cat &
pet(neighbour_dunhill_smoker) = Horse &
pet(neighbour_dunhill_smoker) = Horse &

houseColour(Englishman) = Red &
houseColour(Englishman) = Red &
pet(Swede) = Dog &
pet(Swede) = Dog &
Line 2,765: Line 2,763:
{{out}}
{{out}}
<pre>
<pre>
houseColour = [ {Englishman} Red, {Swede} White, {Dane} Blue, {Norwegian} Yellow, {German} Green ]
houseColour=[ {Englishman} Red, {Swede} White, {Dane} Blue, {Norwegian} Yellow, {German} Green ]
pet = [ {Englishman} Birds, {Swede} Dog, {Dane} Horse, {Norwegian} Cats, {German} Zebra ]
pet =[ {Englishman} Birds, {Swede} Dog, {Dane} Horse, {Norwegian} Cats, {German} Zebra ]
smokes = [ {Englishman} PallMall, {Swede} BlueMaster, {Dane} Blend, {Norwegian} Dunhill, {German} Prince ]
smokes =[ {Englishman} PallMall, {Swede} BlueMaster, {Dane} Blend, {Norwegian} Dunhill, {German} Prince ]
drinks = [ {Englishman} Milk, {Swede} Beer, {Dane} Tea, {Norwegian} Water, {German} Coffee ]
drinks =[ {Englishman} Milk, {Swede} Beer, {Dane} Tea, {Norwegian} Water, {German} Coffee ]
order = [ {First} Norwegian, {Second} Dane, {Third} Englishman, {Fourth} German, {Fifth}, Swede ]
order =[ {First} Norwegian, {Second} Dane, {Third} Englishman, {Fourth} German, {Fifth}, Swede ]
</pre>
</pre>