Example #1
0
    def test_one_game(self):
        all_cards = set()
        old_nsets = -1
        game = sets_solver.one_game()
        for cards in game:
            ncards = cards.shape[1]

            assert ncards % 3 == 0
            
            if ncards < 12:
                # this is only possible at the end of the deck
                left = len(list(game))
                assert left < 3
                
            if cards.shape[1] == 15:
                assert old_nsets == 0
                
            old_nsets = len(sets_solver.find_sets2(cards))
            cards_list = [tuple(c) for c in cards.T]
            all_cards = all_cards.union(set(cards_list))
            
        # all cards must have been played
        cards = [card for card in itertools.product(range(3), repeat=4)]
        assert all_cards == set(cards)
Example #2
0
    def test_one_game(self):
        all_cards = set()
        old_nsets = -1
        game = sets_solver.one_game()
        for cards in game:
            ncards = cards.shape[1]

            assert ncards % 3 == 0

            if ncards < 12:
                # this is only possible at the end of the deck
                left = len(list(game))
                assert left < 3

            if cards.shape[1] == 15:
                assert old_nsets == 0

            old_nsets = len(sets_solver.find_sets2(cards))
            cards_list = [tuple(c) for c in cards.T]
            all_cards = all_cards.union(set(cards_list))

        # all cards must have been played
        cards = [card for card in itertools.product(range(3), repeat=4)]
        assert all_cards == set(cards)
Example #3
0
pylab.gcf().set_size_inches(11, 6.4)
freq, bins, _ = pylab.hist(nsolutions_indep,
                           bins=range(-1, 14),
                           normed=1,
                           hold=0)
pylab.draw()
print 'Prob of 0 sets for the independent case', freq[
    1], 'or 1 in', 1. / freq[1]
#('Prob of 0 sets for the independent case', 0.00038668213395202477, 'or 1 in', 2586.1034482758619)

nsolutions = []
n15 = []
for i in range(5000):
    count15 = 0
    for cards in one_game():
        if cards.shape[1] > 12:
            count15 += 1
            nsolutions.append(len(find_sets2(cards)))
    n15.append(count15)

pylab.gcf().set_size_inches(11, 6.4)
freq, bins, _ = pylab.hist(nsolutions, bins=range(-1, 14), normed=1, hold=0)
pylab.draw()
print 'Prob of 0 sets for 15 cards', freq[1], 'or 1 in', 1. / freq[1]
# ('Prob of 0 sets for 15 cards', 0.010681255698840693, 'or 1 in', 93.621951219512198)

freq, bins, _ = pylab.hist(n15, bins=range(-1, 14), normed=1, hold=0)

print 'number of triplets in 12 cards', scipy.comb(12, 3)
print 'number of new triplets when adding 3 cards', 3 * scipy.comb(
Example #4
0
import pylab
from sets_solver import find_sets2, one_game, random_cards


# distribution of number of sets in random draws
nsolutions_indep = []
for i in range(10000):
    cards = random_cards()
    nsolutions_indep.append(len(find_sets2(cards)))
freq, bins, _ = pylab.hist(nsolutions_indep, bins=range(-1,14), normed=1, hold=0)
print 'Prob of 0 sets for the independent case', freq[1], 'or 1 in', 1./freq[1]

# distribution of number of sets during a game
nsolutions = []
for i in range(5000):
    for cards in one_game():
        nsolutions.append(len(find_sets2(cards)))

freq, bins, _ = pylab.hist(nsolutions, bins=range(-1,14), normed=1, hold=0)
print 'Prob of 0 sets for the game case', freq[1], 'or 1 in', 1./freq[1]

# TODO: are there correlations within games?