So, the homework can be divided into two different parts: comparing the sequences and comparing the result of each sequence. For simplicity's sake let's say that we have
A = ['aacda'], B = ['caaad'], k = 2
we take the map with function ord, obtaining:
A = [97,97,99,100,97], B = [99,97,97,97,100]
Now we compare one to one each element of these lists:
A-B, A-B, A-B, ...
-2, 0, 2, 3, -3
Based on how we have structured the subtraction:
A will get a point if the difference is: 0 < A[x]-B[x] <= 2 or A[x]-B[x] <= -2
B will get a point if the difference is: -2 < A[x]-B[x] <= 0 or A[x]-B[x] >= 2
In this case we have that A will get 2 points and B will get 2 points. We have a tie.
At this point we sum up all the ords of the two lists above, but their result is the same:
So we compare the 2 sequences:
So A wins.
I can't really tell you what you did wrong in your code, you can go down in any of these steps, just ckeck, either with the debugger or a lot of prints for the error in simple cases, hopefully you'll find it before midnight