# -*- Mode: Python -*-

from constraint import *

# http://brownbuffalo.sourceforge.net/index.html
#
# Title: Arch Friends
# Author: Mark T. Zegarelli
# Publication: Dell Logic Puzzles
# Issue: April, 1998
# Page: 7
# Stars: 1
# 
# Harriet, upon returning from the mall, is happily describing her
# four shoe purchases to her friend Aurora. Aurora just loves the four
# different kinds of shoes that Harriet bought (ecru espadrilles,
# fuchsia flats, purple pumps, and suede sandals), but Harriet can't
# recall at which different store (Foot Farm, Heels in a Handcart, The
# Shoe Palace, or Tootsies) she got each pair. Can you help these two
# figure out the order in which Harriet bought each pair of shoes, and
# where she bought each?

# 1. Harriet bought fuchsia flats at Heels in a Handcart.
# 2. The store she visited just after buying her purple pumps was not Tootsies.
# 3. The Foot Farm was Harriet's second stop.
# 4. Two stops after leaving The Shoe Place, Harriet bought her suede sandals.

# Determine: Order - Shoes - Store 

p = Problem()

map = {
    'E': 'ecru espardilles',
    'F': 'fuchsia flats',
    'P': 'purple pumps',
    'S': 'suede sandals',
    'f': 'The Foot Farm',
    'h': 'Heels in a Handcart',
    'p': 'The Shoe Palace',
    't': 'Tootsies',
    }

order = [1,2,3,4]

p.addVariables (map.keys(), order)

p.addConstraint (AllDifferentConstraint(), "EFPS")
p.addConstraint (AllDifferentConstraint(), "fhpt")

pa = p.addConstraint

# 1. Harriet bought fuchsia flats at Heels in a Handcart.
pa (lambda F,h: F == h, "Fh")
# 2. The store she visited just after buying her purple pumps was not Tootsies.
pa (lambda P,t: P+1 != t, "Pt")
# 3. The Foot Farm was Harriet's second stop.
pa (lambda f: f == 2, "f")
# 4. Two stops after leaving The Shoe Place, Harriet bought her suede sandals.
pa (lambda p,S: p+2 == S, "pS")

solution = p.getSolutions()[0]
solution = [(v,k) for (k,v) in solution.items()]
solution.sort()
for i in range (4):
    print i,
    for j in range (2):
        v,k = solution.pop(0)
        print map[k] + ',',
    print
