Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # End of first game where we were stumped with 12 cards
- cards1 = map(lambda x:x.split(), [
- 'oval 2 red filled',
- 'diamond 3 purple hollow',
- 'oval 2 green filled',
- 'wave 3 red filled',
- 'wave 2 green semi',
- 'diamond 1 purple semi',
- 'oval 1 purple hollow',
- 'diamond 2 red filled',
- 'oval 3 green hollow',
- 'oval 3 purple hollow',
- 'diamond 1 green hollow',
- 'diamond 1 red hollow'
- ])
- # End of second game where we were stumped with 12 cards
- cards2 = map(lambda x:x.split(), [
- 'oval 2 red semi',
- 'wave 3 red hollow',
- 'wave 1 green hollow',
- 'diamond 2 purple hollow',
- 'oval 2 green semi',
- 'oval 3 red filled',
- 'diamond 2 red filled',
- 'diamond 1 red semi',
- 'wave 2 green semi',
- 'diamond 1 green semi',
- 'diamond 2 purple filled',
- 'diamond 3 green semi'
- ])
- def getCombinations(cards):
- output = []
- total = len(cards)
- i = 0
- while i < total:
- j = i + 1
- while j < total:
- k = j + 1
- while k < total:
- if i != j and j != k and i != k:
- output.append((cards[i], cards[j], cards[k]))
- k = k + 1
- j = j + 1
- i += 1
- return output
- def isSet(cardTriple):
- card1, card2, card3 = cardTriple
- i = 0
- while i < 4:
- a = card1[i]
- b = card2[i]
- c = card3[i]
- if a == b and b == c:
- pass # all 3 cards match for this quality
- elif a != b and b != c and a != c:
- pass # none of the cards match for this quality
- else:
- return False # some of the cards match but not all --> NOT A SET
- i += 1
- return True
- for cards in (cards1, cards2):
- print filter(isSet, getCombinations(cards))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement