Files
pplus-library/modules/align/needleman-wunsch-score/ref/mojo/plain.mojo
T
alexm 568474d52f
Test (in pplus-core) / in-core (push) Failing after 28m44s
Initial commit
2026-11-12 22:23:48 -05:00

26 lines
895 B
Mojo

def needleman_wunsch_score(s: String, t: String, match_: Int, mismatch: Int, gap: Int) -> Int:
var n = s.count_codepoints()
var m = t.count_codepoints()
var d = List[List[Int]]()
for i in range(n + 1):
var row = List[Int]()
for j in range(m + 1):
row.append(0)
d.append(row^)
for i in range(n + 1):
d[i][0] = i * gap
for j in range(1, m + 1):
d[0][j] = j * gap
for i in range(1, n + 1):
for j in range(1, m + 1):
var score = mismatch
if String(s[codepoint=i - 1]) == String(t[codepoint=j - 1]):
score = match_
var best = d[i - 1][j - 1] + score
if d[i - 1][j] + gap > best:
best = d[i - 1][j] + gap
if d[i][j - 1] + gap > best:
best = d[i][j - 1] + gap
d[i][j] = best
return d[n][m]