juliomarcos

Untitled

Apr 3rd, 2013
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. import collections, itertools
  2.  
  3. def isFromBananania(t):
  4.    c = collections.defaultdict(int)
  5.    for x in t:
  6.       c[x] += 1
  7.       if c['b'] > c['a']:
  8.          return False
  9.    if c['b'] == c['a']:
  10.       return True
  11.    else:
  12.       return False
  13.  
  14. def generateBanananiaElection(n):
  15.    l = itertools.product('ab', repeat=n)
  16.    for t in l:
  17.       if isFromBananania(t):
  18.          print ''.join(t)
  19.  
  20. if __name__ == "__main__":
  21.    for i in [x+1 for x in range(5)]:
  22.       print i*2
  23.       generateBanananiaElection(i*2)
Advertisement
Add Comment
Please, Sign In to add comment