0

My code works perfectly when I run it through check50, and if I compare the strings using "./score FILE1 FILE2" with the words "cat" and "ate" the number of operations returned is 2 - which is correct. It also handles strings of different lengths perfectly. However, if I do the same thing except on the web app, it comes out like this:

compare cat and ate output

also, if I try to input strings of differing length, I get:

enter image description here

I have no idea where I should look in my code to fix this issue. I'm sure it has nothing to do with matrix.html as this happens even if it is empty. I guess it could be related to index.html but I'm not sure where. Any help is appreciated!

1 Answer 1

0

You got the distance (the number in the tuple) right, but the operations wrong. check50 probably tests the distance only, since there often are multiple correct paths (e.g. "ab"=>"ba" could be insert,copy,delete, or delete,copy,insert, or substitute,substitute all with cost of 2), and it would have to check consistency of the matrix, not just compare it to a predefined result.

The operation indicates where to find the predecessor cell. For example, Substituted means the previous cell was one left, one up. Inserted would mean one left. You get the error because the algorithm for display tried to walk the way you told it, but it hit a wall (your matrix[0][0] element is not (0, None) as it should be, so it continues and tries to access negative indices).

Have you implemented the matrix display? (You assume right that it wouldn't change your problem, you just did not show a screenshot of that TODO section, maybe because it doesn't show what went wrong)

2
  • Thank you so much. I understood everything you said here, but you going through it helped a lot and now it works! What I did wrong is I surrounded Operation.x in quotation marks, which was incorrect.
    – Elliot
    Commented Apr 17, 2018 at 15:07
  • Common mistake for beginners (who in this case are not familiar with Python enums), statically typed languages like C catch most of them, but languages like Python or JavaScript are not so strict. You can see that the mistake does not happen on display, but in the Python code using your matrix, which follows the information to assemble the path of changes. This indicates something's wrong in the matrix. And it's not the numbers, which, at least the one in the lower right corner, are tested in check50.
    – Blauelf
    Commented Apr 17, 2018 at 15:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .