Inspired by Computer Science forum post, I did this code. I prepared it Shedskin compatible, and it runs quite nicely indeed. Even interpreted the algorithm is faster than full sort. Here interpreted test for the module, shedskinning this test would show better time for sort solution. Python version has benefit of being able to take any sequence as input and return. [CODE]from __future__ import print_function from random import randint import time from kth_biggest import * if __name__ == '__main__': # second biggest 4 is 5th smallest assert kth_biggest([4,3,1,2,3,5], 2) == kth_smallest([4,3,1,2,3,5],5) # random amount, max_items = 16, 1000000 print('Testing %i … |
+0 forum
3 | ||

Here is Mandelbrot set viewer in Tkinter and modules for shedskining (included compiled modules for windows in the zip file): [CODE]# mandelsh.py def mandel(real, imag, max_iterations=20): '''determines if a point is in the Mandelbrot set based on deciding if, after a maximum allowed number of iterations, the absolute value of the resulting number is greater or equal to 2.''' z_real, z_imag = 0.0, 0.0 for i in range(0, max_iterations): z_real, z_imag = ( z_real*z_real - z_imag*z_imag + real, 2*z_real*z_imag + imag ) if (z_real*z_real + z_imag*z_imag) >= 4: return i % max_iterations return -1 res = 0 res = mandel(1.0, … |
+0 forum
7 |

The End.