Skip to content

Instantly share code, notes, and snippets.

@touhi99
Created June 11, 2018 22:18
Show Gist options
  • Save touhi99/ca72e6250c9c62cb44a0ca2344aa5cbb to your computer and use it in GitHub Desktop.
Save touhi99/ca72e6250c9c62cb44a0ca2344aa5cbb to your computer and use it in GitHub Desktop.
#prod -> right-hand side one element
nt -> left-hand side non-terminal
count -> true, if prod is in left
def create_prod_combinations(prod, nt, count):
numset = 1 << count
new_prods = []
for i in range(numset):
nth_nt = 0
new_prod = ''
for s in prod:
if s == nt:
if i & (1 << nth_nt):
new_prod = new_prod+s
nth_nt += 1
else:
new_prod = new_prod+s
new_prods.append(new_prod)
return new_prods
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment