Skip to content

Instantly share code, notes, and snippets.

@akaptur
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akaptur/3528d9911054bd75eaf4 to your computer and use it in GitHub Desktop.
Save akaptur/3528d9911054bd75eaf4 to your computer and use it in GitHub Desktop.
def countdown(n, times_called=[0]):
print times_called[0], " ", n, " "
times_called[0] += 1
if n == 1:
return times_called
else:
try:
return countdown(n-1)
except RuntimeError:
print "\nexception at %s" % times_called[0]:
return countdown(n-1)
print(countdown(1010))
@akaptur
Copy link
Author

akaptur commented Oct 13, 2014

output:

exception at 141739
141739   5  
141740   4  
141741   3  
141742   2  

exception at 141743
141743   2  

exception at 141744
141744   3  
141745   2  

exception at 141746
141746   2  

exception at 141747
141747   4  
141748   3  
141749   2  

exception at 141750
141750   2  

exception at 141751
141751   3  
141752   2  
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment