This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (*Background: Given 2 strings, compute an alignment that maximises their similarity score. | |
| Each of the two sequences being compared, x and y, is modified by inserting spaces at arbitrary | |
| locations, including at either end, so that the resulting sequences ,x0 and y0, | |
| are of the same length k but do not have a space in the | |
| same position i.e. for no position j are both x0[j] and y0[j] a space | |
| *) | |
| (* Task 1 *) | |
| (* | |
| Helper function to calculate the alignment score of two strings, starting from a given position |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def extended_gcd(aa, bb): | |
| lastremainder, remainder = abs(aa), abs(bb) | |
| x, lastx, y, lasty = 0, 1, 1, 0 | |
| while remainder: | |
| lastremainder, (quotient, remainder) = remainder, divmod(lastremainder, remainder) | |
| x, lastx = lastx - quotient*x, x | |
| y, lasty = lasty - quotient*y, y | |
| return lastremainder, lastx * (-1 if aa < 0 else 1), lasty * (-1 if bb < 0 else 1) | |
| def modinv(a, m): |