我如何实现在 weasle 程序中看到的评分算法(Richard Dawkins)

How do I implement the scoring algorithm seen in the weasle program (by Richard Dawkins)

需要一些关于我正在研究的评分算法的建议。我基本上是在尝试实现在 weasel 程序中看到的评分算法 (https://en.wikipedia.org/wiki/Weasel_program)

Compare each new string with the target string " (any given string) ", and give each a score (the number of letters in the string that are correct and in the correct position).

我认为您可以根据字符的 ASCII 值对字符串进行评分,但我如何知道字符是否位于正确的位置?

在 Weasel 程序中,您不关心位置 - 您只需将两个字符串并排放置,然后一个字母一个字母地放置。他们平等吗?分数加一。他们有什么不同吗? D没什么。它基本上是 L - h(target, candidate),其中 L 是字符串的长度,h 是两个字符串之间的 Hamming distance

这是唯一可能的,因为大小是固定的,因此您可以并排对齐字符串。如果长度不固定,您将需要使用不同的字符串距离度量,以允许比较不同大小的字符串,例如Levenshtein (edit) distance.