Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # balance_detect_2.py
- import random
- from itertools import permutations
- brackets = permutations(['(','X',')']*3)
- brackets = list(set(brackets))
- random.shuffle(brackets)
- balance_count = 0
- for i in brackets:
- balance_check = 0
- sss = ''.join(i)
- p = ''
- for s in sss:
- if s == '(':
- balance_check += 1
- elif s == ')':
- balance_check -= 1
- if balance_check < 0:
- break
- else:
- if p == 'X':
- balance_check = -1
- break
- p = s
- 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