Want more features on Pastebin? Sign Up, it's FREE!
Guest

watsort

By: a guest on Sep 17th, 2012  |  syntax: Python  |  size: 0.43 KB  |  views: 1,838  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import sys
  2.  
  3. def it(i, n):
  4.         yield None
  5.         if (i > 0):
  6.                 for j in it(i-1, n):
  7.                         yield j
  8.         else:
  9.                 yield n
  10.  
  11.  
  12. def Sort(its):
  13.         done = False
  14.         while not done:
  15.                 done = True
  16.                 for i in its:
  17.                         try:
  18.                                 val = i.next()
  19.                                 if val == None:
  20.                                         done = False
  21.                                 else:
  22.                                         yield val
  23.                         except:
  24.                                 its.remove(i)
  25.  
  26. iters = []
  27. for arg in sys.argv[1:]:
  28.         num = int(arg)
  29.         iters.append(it(num, num))
  30.  
  31. for i in Sort(iters):
  32.         print i
clone this paste RAW Paste Data