def find_paths(n): global rights global downs global current_path path_list = [] while downs < 3 and rights < 3: go_right() go_down() if downs == 2 and rights == 2: if not(current_path in path_list): path_list.append(current_path) paths = paths + 1 print current_path current_path = [] find_paths(n) def go_right(): global current_path global rights global downs if rights < 3: rights = rights + 1 current_path.append("right") go_right() go_down() else: go_down() def go_down(): global current_path global rights global downs if downs < 3: downs = downs + 1 current_path.append("left") go_right() go_down() else: go_right() rights = 0 downs = 0 current_path = [] find_paths(2)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question