Invoke thusly
$ python bogo.py
Then, enjoy!
You can edit the lines:
CPUS = 4 LEN = 10
to suit your desires.
Yo, check it.
| #!/usr/bin/env python | |
| # Bogosort in Python | |
| # It's for fun! | |
| # Austin Glenn Davis-Richardson | |
| LEN = 6 | |
| CPUS = 2 | |
| from random import * | |
| from multiprocessing import Pool | |
| import sys | |
| def main(): | |
| while True: | |
| pool = Pool(processes = CPUS) | |
| result = pool.apply_async(find_one, [LEN]) | |
| print result.get() | |
| def find_one(len=LEN): | |
| b = tuple(range(0,len)) | |
| count = 0 | |
| while True: | |
| items = range(0,len) | |
| shuffle(items) | |
| items = tuple(items) | |
| count += 1 | |
| if items == b: | |
| break | |
| return count | |
| if __name__ == '__main__': | |
| try: | |
| main() | |
| except KeyboardInterrupt: | |
| print >> sys.stderr, '\nUser Exited!\n' |