Created
April 19, 2015 02:15
-
-
Save ericdorsey/96a0ce65e4b51b6177db to your computer and use it in GitHub Desktop.
Inception in Python
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
def inception(target_depth, current_depth=0, going_deeper=True): | |
if going_deeper == True: | |
if current_depth < target_depth: | |
current_depth += 1 | |
if current_depth != target_depth: | |
print("Dream Level: {0}, going deeper..".format(current_depth)) | |
elif current_depth == target_depth: | |
print("Dream Level: {0}, coming back up..".format(current_depth)) | |
return inception(target_depth, current_depth, True) | |
elif current_depth == target_depth: | |
return inception(target_depth, current_depth, False) | |
elif going_deeper == False: | |
current_depth -= 1 | |
if current_depth != 0: | |
print("Dream Level: {0}, coming back up..".format(current_depth)) | |
return inception(target_depth, current_depth, False) | |
if current_depth == 0: | |
print("No dream level, back at reality.") | |
return | |
print("") | |
inception(4) | |
print("") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example output: