Drop the Triples
The game is played between two players, with a set of standard playing cards. Cards are distinguished only by their values, from 1 (Ace) to 13 (King). The cards are shuffled and placed as a pile in the center of the table, face down. This pile is called the stock. The two players take turns at playing. At each turn, a player
●draws the top card from the stock, adding it to her/his hand; and
●decides whether she/he wants to "drop some triples"
Dropping a triple consists of choosing three cards (a triple) from the hand and placing them on the table, face up. The dropped triples stay on the table until the end of the game.
Only some sets of three cards form a valid triple. There are two types of valid triples:
●Perfect triples are made of three cards whose values represent the length of sides of an equilateral triangle;
●Common triples are made by three cards whose values represent the length of sides of any other (not equilateral) triangle.
The figure below shows examples of perfect triples (a), common triples (b), and invalid triples(c).
Only valid triples can be dropped, but a player may drop any number of triples at a given turn. In particular, since players know the number of cards in the stock at every turn, a player may decide to drop all triples in her/his last turn. Some players, however, normally drop some triples during the game, to maintain as few cards in their hands as possible.
The game finishes when the stock is empty. The winner is the player that dropped the largest number of perfect triples. If both players dropped the same number of perfect triples, the winner is the player that dropped the largest number of common triples. If both players dropped the same number of perfect triples and the same number of common triples, the result is a tie.
Given the description of the cards in the stock, write a program that determines the winner of a game of Triples, considering both players play as best as possible.
7 5 6 5 6 5 6 8 12 13 13 13 13 13 13 1 3 2 9 3 9 12 1 2 1 2 1 2 3 1 4 2 5 3 0
0 2 1