parent
1e4093d949
commit
42d2c3088e
12 changed files with 135 additions and 19 deletions
|
|
@ -13,10 +13,11 @@
|
|||
import unicode
|
||||
|
||||
proc editDistance*(a, b: string): int {.noSideEffect.} =
|
||||
## Returns the unicode-rune edit distance between ``a`` and ``b``.
|
||||
## Returns the **unicode-rune** edit distance between ``a`` and ``b``.
|
||||
##
|
||||
## This uses the `Levenshtein`:idx: distance algorithm with only a linear
|
||||
## memory overhead.
|
||||
runnableExamples: static: doAssert editdistance("Kitten", "Bitten") == 1
|
||||
if len(a) > len(b):
|
||||
# make ``b`` the longer string
|
||||
return editDistance(b, a)
|
||||
|
|
@ -181,6 +182,7 @@ proc editDistanceAscii*(a, b: string): int {.noSideEffect.} =
|
|||
##
|
||||
## This uses the `Levenshtein`:idx: distance algorithm with only a linear
|
||||
## memory overhead.
|
||||
runnableExamples: static: doAssert editDistanceAscii("Kitten", "Bitten") == 1
|
||||
var len1 = a.len
|
||||
var len2 = b.len
|
||||
if len1 > len2:
|
||||
|
|
|
|||
|
|
@ -54,6 +54,14 @@ func sumPairs*[T](x: openArray[T]): T =
|
|||
if n == 0: T(0) else: sumPairwise(x, 0, n)
|
||||
|
||||
|
||||
runnableExamples:
|
||||
static:
|
||||
block:
|
||||
const data = [1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
doAssert sumKbn(data) == 45
|
||||
doAssert sumPairs(data) == 45
|
||||
|
||||
|
||||
when isMainModule:
|
||||
from math import pow
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue