Created
June 11, 2018 22:18
-
-
Save touhi99/ca72e6250c9c62cb44a0ca2344aa5cbb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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