May-21-2020, 07:13 PM
Hello! I need to convert this C code I made to Python:
https://gist.github.com/anakk1n/dadf2216...10c3839af5
My python code looks like this:
Problem is that it doesn't list 100% the same thing. Did i do anything wrong in the conversion? Also, I changed the 'l' variable in the C code with the 'c' variable in python and in Python I made it return 'c', but it shouldn't affect my result
https://gist.github.com/anakk1n/dadf2216...10c3839af5
My python code looks like this:
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 |
def algoritm2(v, n, d, c): p = 0 j = - 3 k = 0 for i in range (n - 1 ): if (j > = n - 2 ): break if (p = = 1 ): print (v[j + 1 ], " " , end = '') u = k = v[j + 1 ] i = j + 1 c = c + 1 p = 0 else : u = - 1 j = i aux = v[i] + d + 1 if (aux < = v[i + 1 ] and u = = - 1 ): print (v[i], " " , end = '') k = v[i] c = c + 1 else : if (((v[i] - v[i - 1 ] > = d) and u ! = v[i]) or (i = = 0 )): k = v[i] print (v[i], " " , end = '') c = c + 1 while (aux > v[j + 1 ] and j < n - 2 ): j = j + 1 p = 1 if (v[n - 1 ] - k > = d + 1 ): print (v[n - 1 ], " " , end = '') return c |