Skip to content

Commit

Permalink
Add Walk
Browse files Browse the repository at this point in the history
  • Loading branch information
neurlang authored and Your Name committed Jun 13, 2024
1 parent d0e0676 commit 43e5338
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions walk.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package levenshtein

func Walk[T Number](mat []T, width uint, to func(uint, uint)) {
pos := uint(len(mat) - 1)
x := (pos % width)
y := (pos / width)
for x > 0 && y > 0 {
diag := x - 1 + width*(y-1)
up := x + width*(y-1)
left := x - 1 + width*(y)
if diag >= 0 {
if mat[diag] < mat[left] && mat[diag] < mat[up] {
x--
y--
to(x, y)
continue
}
}
if left >= 0 && up >= 0 {
if mat[up] < mat[left] {
y--
to(x, y)
continue
} else {
x--
to(x, y)
continue
}
}
if left >= 0 {
x--
to(x, y)
continue
}
if up >= 0 {
y--
to(x, y)
continue
}
}
}

0 comments on commit 43e5338

Please sign in to comment.