Skip to content

Instantly share code, notes, and snippets.

@silveira
Last active December 11, 2015 09:48
Show Gist options
  • Save silveira/4582591 to your computer and use it in GitHub Desktop.
Save silveira/4582591 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
counter = 0
def parentheses(symbol='(', depth=0, n=5):
global counter
counter += 1
if(depth<n*2):
parentheses(symbol+'(', depth+1, n)
parentheses(symbol+')', depth+1, n)
elif (depth==n*2):
print symbol
if __name__=="__main__":
parentheses()
print counter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment