1  #!/usr/bin/python
 2  #
 3  #
 4
 5  import sys
 6
 7
 8  boarddata =  ["3pdf", '1pdl', '3pof', '2psc', '1pol', '1gsc', '1gdl', '1gsl', '2rsc', '2pof', '1psc', '3psc']
 9  #boarddata =  ["3pdf", '2gdf', '1srf', '1pdl', '3rdc', '1rol', '2goc', '1goc', '2gdf', '1psl', '2gol', '1rsl']
10
11  class card:
12     def __init__(self, ncsf):
13        self.number = ncsf[0]
14        self.color = ncsf[1]
15        self.shape = ncsf[2]
16        self.filltype = ncsf[3]
17
18     def printMe(self):
19        print "Number", self.number, "Color",self.color, "Shape", self.shape, "Fill", self.filltype
20
21  def compare_two_attribute(a1,a2):
22     return (a1 == a2) or (a1 != a2)
23
24  def compare_two(c1,c2):
25     #check for agreement or disagreement
26     return compare_two_attribute(c1.color,c2.color) \
27              and compare_two_attribute(c1.shape,c2.shape) \
28              and compare_two_attribute(c1.number,c2.number) \
29              and compare_two_attribute(c1.filltype,c2.filltype)
30
31  def compare_three_attribute(a1,a2,a3):
32     return ((a1 == a2) and (a2 == a3)) or ((a1 != a2) and (a2 != a3) and (a1 != a3))
33
34  def compare_three(c1,c2,c3):
35     #check for agreement or disagreement of color
36     return compare_three_attribute(c1.color,c2.color,c3.color) \
37              and compare_three_attribute(c1.shape,c2.shape,c3.shape) \
38              and compare_three_attribute(c1.number,c2.number,c3.number) \
39              and compare_three_attribute(c1.filltype,c2.filltype,c3.filltype)
40
41
42
43  board = []
44  for str in boarddata:
45     c = card(str)
46     board.append(c)
47  l = len(board)
48  for a in range(0,l):
49     for b in range(a+1,l):
50        # if a b together can't possibly be a set,
51        # why bother searching with a 3rd one?
52        if compare_two(board[a],board[b]):
53           for c in range(b+1,l):
54              if compare_three(board[a],board[b],board[c]):
55                 print "Found the set of:"
56                 print a, b, c
57                 board[a].printMe()
58                 board[b].printMe()
59                 board[c].printMe()
60                 print
61                 print
62