permutation code in C and python