Home More Samples
```///////////////////////////////////////////////////////////////////////////////
//
// Title: Signing Off
// Author: Scott Marley
// Publication: Dell Logic Puzzles
// Issue: April, 1998
// Page: 37
// Stars: 4
//
// Compass County contains 10 small towns, as shown in the map below. The towns
// (named Kuhery, Layton, Mungle, Nicket, Pravil, Quabba, Ridder, Skoque, Tudora,
// and Vydorf) are linked by roads which are mostly north-south and east-west,
// complicated somewhat by three bends as shown ("the + signs"). Ten new
// directional signs have been painted, one to be placed in each town. Each sign
// tells how to get to one or two other towns, in each case by traveling along a
// single road -- provided that if you reach one of the road bends, you follow it
// and then continue in the new direction. For example, a sign in town C might
// direct you east to town D or E, or it might direct you north to town A, B, H,
// or J. The woman in charge of erecting the signs has them all stacked in the
// back of her pickup truck and is ready to go, but unfortunately she was given a
// map that doesn't show which sign belongs to each town, or even which town is
// which.
// Can you help her out by matching each lettered town on the map with its
// name and sign?
//
//
// + -- A -- B ---+
// |    |    |    |             N
// C -- D -- E    |           W   E
//      |    |    |             S
//      F -- G -- H
//      |    |    |
//      + -- I -- J
//
// |  is a north-south road
// -- is an east-west road
// +  is a bend in the road, not a town
//
// (view with a non-proportional font)
//
// Signs:
// 1.  NORTH TO KUHERY
//     WEST TO TUDORA
//
// 2.  NORTH TO LAYTON
//     EAST TO VYDORF
//
// 3.  NORTH TO NICKET
//     SOUTH TO SKOQUE
//
// 4.  NORTH TO QUABBA
//     WEST TO KUHERY
//
// 5.  EAST TO LAYTON
//     EAST TO NICKET
//
// 6.  NORTH TO MUNGLE
//
// 7.  NORTH TO SKOQUE
//
// 8.  EAST TO VYDORF
//
// 9.  SOUTH TO RIDDER
//
// 10. WEST TO PRAVIL
//
///////////////////////////////////////////////////////////////////////////////
//
// Query:
//          all SigningOff(sign,town)
//
///////////////////////////////////////////////////////////////////////////////
//
// Result:
//
// sign = [ {Kuhery} 5, {Layton} 4, {Mungle} 8, {Nicket} 10, {Pravil} 2,
//          {Quabba} 1, {Ridder} 7, {Skoque} 9, {Tudora} 6, {Vydorf} 3]
//
// town = [ {Kuhery} A, {Layton} J, {Mungle} D, {Nicket} B, {Pravil} C,
//          {Quabba} H, {Ridder} Y, {Skoque} G, {Tudora} F, {Vydorf} E]
//
///////////////////////////////////////////////////////////////////////////////
//
// Note: The letter "I" is reserved, so we use "Y" instead.
//
///////////////////////////////////////////////////////////////////////////////
local Town = Kuhery | Layton | Mungle | Nicket | Pravil | Quabba | Ridder |
Skoque | Tudora | Vydorf

local Letter = A | B | C | D | E | F | G | H | Y | J  // Y instead of I

local Towns = Town->>Letter
local Signs = Town->>[1..10]

pred SigningOff(sign::Signs,town::Towns) iff

// 1.  NORTH TO KUHERY
//     WEST TO TUDORA

sign(x1) = 1 & town(x1) = y1 &
North(town(Kuhery),y1) & West(town(Tudora),y1) &

// 2.  NORTH TO LAYTON
//     EAST TO VYDORF

sign(x2) = 2 & town(x2) = y2 &
North(town(Layton),y2) & East(town(Vydorf),y2) &

// 3.  NORTH TO NICKET
//     SOUTH TO SKOQUE

sign(x3) = 3 & town(x3) = y3 &
North(town(Nicket),y3) & South(town(Skoque),y3) &

// 4.  NORTH TO QUABBA
//     WEST TO KUHERY

sign(x4) = 4 & town(x4) = y4 &
North(town(Quabba),y4) & West(town(Kuhery),y4) &

// 5.  EAST TO LAYTON
//     EAST TO NICKET

sign(x5) = 5 & town(x5) = y5 &
East(town(Layton),y5) & East(town(Nicket),y5) &

// 6.  NORTH TO MUNGLE

sign(x6) = 6 & town(x6) = y6 &
North(town(Mungle),y6) &

// 7.  NORTH TO SKOQUE
sign(x7) = 7 & town(x7) = y7 &
North(town(Skoque),y7) &

// 8.  EAST TO VYDORF
sign(x8) = 8 & town(x8) = y8 &
East(town(Vydorf),y8) &

// 9.  SOUTH TO RIDDER
sign(x9) = 9 & town(x9) = y9 &
South(town(Ridder),y9) &

// 10. WEST TO PRAVIL
sign(x10) = 10 & town(x10) = y10 &
West(town(Pravil),y10)

///////////////////////////////////////////////////////////////////////////////
// t is East of x. (x cannot be E,H,J)
//
// + -- A -- B ---+
// |    |    |    |             N
// C -- D -- E    |           W   E
//      |    |    |             S
//      F -- G -- H
//      |    |    |
//      + -- I -- J
//
local pred East(t::Letter,x::Letter) iff
(x = A & (t = B | t = H | t = J)) |  // one bend
(x = B & (t = H | t = J)) |          // one bend
(x = C & (t = D | t = E)) |
(x = D & t = E) |
(x = F & (t = G | t = H)) |
(x = G & t = H) |
(x = Y & t = J)

///////////////////////////////////////////////////////////////////////////////
// t is West of x. (x cannot be C,F)
//
// + -- A -- B ---+
// |    |    |    |             N
// C -- D -- E    |           W   E
//      |    |    |             S
//      F -- G -- H
//      |    |    |
//      + -- I -- J
//
local pred West(t::Letter,x::Letter) iff
(x = A & t = C) |
(x = B & (t = A | t = C)) |
(x = D & t = C ) |
(x = E & (t = C | t = D)) |
(x = G & t = F) |
(x = H & (t = F | t = G))|
(x = Y & (t = F | t = D | t = A)) |         // bend
(x = J & (t = Y | t = F | t = D | t = A))   // bend

///////////////////////////////////////////////////////////////////////////////
// t is North of x (x cannot be A,B)
//
// + -- A -- B ---+
// |    |    |    |             N
// C -- D -- E    |           W   E
//      |    |    |             S
//      F -- G -- H
//      |    |    |
//      + -- I -- J
//
local pred North(t::Letter,x::Letter) iff
(x = C & (t = A | t = B | t = H | t = J)) |
(x = D & t = A) |
(x = E & t = B) |
(x = F & (t = D | t = A)) |
(x = G & (t = E | t = B)) |
(x = H & (t = A | t = B | t = C)) |         // two bends
(x = Y & (t = G | t = E | t = B)) |
(x = J & (t = H | t = B | t = A | t = C))   // two bends

///////////////////////////////////////////////////////////////////////////////
// t is South of x (x cannot be C,I,J)
//
// + -- A -- B ---+
// |    |    |    |             N
// C -- D -- E    |           W   E
//      |    |    |             S
//      F -- G -- H
//      |    |    |
//      + -- I -- J
//
local pred South(t::Letter,x::Letter) iff
(x = A & (t = D | t = F | t = Y | t = J)) | // one bend
(x = B & (t = E | t = G | t = Y)) |
(x = D & (t = F | t = Y | t = J)) |
(x = E & (t = G | t = Y)) |
(x = F & (t = Y | t = J)) |                 // one bend
(x = G & t = Y) |
(x = H & t = J)

```