Created
October 25, 2012 03:32
-
-
Save ianb/3950268 to your computer and use it in GitHub Desktop.
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
import threading | |
try: | |
from Queue import Queue | |
except ImportError: | |
from queue import Queue | |
def fact(n, queue=None): | |
if n == 0 or n == 1: | |
if queue: | |
queue.put(1) | |
return | |
else: | |
return 1 | |
q = Queue() | |
t = threading.Thread(target=fact, args=(n - 1, q)) | |
t.start() | |
result = q.get() * n | |
if queue: | |
queue.put(result) | |
return | |
else: | |
return result | |
if __name__ == "__main__": | |
import sys | |
print (fact(int(sys.argv[1]))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment