Skip to content

Instantly share code, notes, and snippets.

@audy
Created June 1, 2010 20:03
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 audy/421402 to your computer and use it in GitHub Desktop.
Save audy/421402 to your computer and use it in GitHub Desktop.
Bogosort, Multiprocessed.

BOGO

Invoke thusly

$ python bogo.py

Then, enjoy!

You can edit the lines:

CPUS = 4 LEN = 10

to suit your desires.

What Bogosort is?

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'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment