View difference between Paste ID: kBDKLKYz and 3La6BNPF
SHOW: | | - or go back to the newest paste.
1
import sys
2
3
def gen_games(i):
4
    if i == 1:
5-
        yield [0]
5+
        yield 'A'
6-
        yield [1]
6+
        yield 'B'
7
    else:
8
        for game in gen_games(i-1):
9-
            yield [0] + game
9+
            yield 'A' + game
10-
            yield [1] + game
10+
            yield 'B' + game
11
12
def shorten(count, l):
13
    for i in range(count, len(l)):
14-
        if l[:i].count(0) == count or l[:i].count(1) == count:
14+
        if l[:i].count('A') == count or l[:i].count('B') == count:
15
            return l[:i]
16
    return l
17
18
if __name__=='__main__':
19
    if len(sys.argv) > 1:
20
        length = int(sys.argv[1])
21
        closed = set()
22-
            print shorten(length, game)
22+
23
            game = shorten(length, game)
24
            if game not in closed:
25
                closed.add(game)
26
                print game