codepad | about

Project:
 Link:    [ raw code | fork ]

Python, pasted on May 4:
 ```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 ``` ```import sys import random def isodd(num): return bool(num & 1) def parteo(a): even = 0 odd = len(a) - 1 while even < odd: if isodd(a[even]): if isodd(a[odd]): odd = odd-1 else: t = a[odd] a[odd] = a[even] a[even] = t even = even + 1 odd = odd - 1 else: even = even + 1 return a def val_parteo(a): in_odd = False for idx in range(len(a)): if isodd(a[idx]): in_odd = True; elif in_odd: return idx return -1 def gen_arr(size): a=[] for idx in range(size): a.append(random.randint(1,1000)) return a def check_alg(): for size in range(1,20): for tst in range(1,5): arr = gen_arr(size); print ">",arr part = parteo(arr[:]); print "<",part bad_idx = val_parteo(part); if bad_idx != -1: print "Bug found", arr, "\n", part, "\nError at", idx check_alg() print "Finished" ```

Comments: