Skip to content

Instantly share code, notes, and snippets.

@prat0318
Last active December 27, 2015 05:39
Show Gist options
  • Save prat0318/7276291 to your computer and use it in GitHub Desktop.
Save prat0318/7276291 to your computer and use it in GitHub Desktop.
Usage: paren(0,4,'')
#Usage: paren(0,4,'')
def paren(sum,remaining,str):
if sum < 0:
return
if remaining == 0:
print str+')'*sum
return
paren(sum+1,remaining-1,str+'(')
paren(sum-1,remaining,str+')')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment