Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # balance_detect.py
- import random
- from itertools import permutations
- brackets = permutations(['(',')']*5)
- brackets = list(set(brackets))
- random.shuffle(brackets)
- balance_count = 0
- for i in brackets:
- balance_check = 0
- sss = ''.join(i)
- for s in sss:
- if s == '(':
- balance_check += 1
- else:
- balance_check -= 1
- if balance_check < 0:
- break
- balance_check = 'no' if balance_check else 'yes'
- if balance_check == 'yes': balance_count += 1
- print(sss + ' ' + balance_check)
- print(str(balance_count) + ' ' + str(len(brackets)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement