Quiz String Similarity
Author |
Message |
AlexKabam
|
Posted: Tue Feb 23, 2016 11:19 am Post subject: Quiz String Similarity |
|
|
What is it you are trying to achieve?
I am trying to create a Quiz Program, however to receive a high mark beyond using the index function I would like to develop a string similarity algorithm.
What is the problem you are having?
I am unable to create an algorithm that will adjust for potential extra characters
Describe what you have tried to solve this problem
I have tried following Levenschtein tutorials for C however I do not understand how they would work with an extra character at the beginning. (see my code below)
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
[syntax="turing"]
<Add your code here>
function distance (answer : string, lenAnswer : int, lenGuess : int, guess : string) : int
var cost : int := 0
var longerWord : int
if lenGuess = 0
then
result cost
end if
if lenAnswer = 0
then
result cost
end if
longerWord := max (length (answer), (length (guess)))
for decreasing i : longerWord .. 1
if guess(i) = answer(i)
then cost += 0
else
cost += 1
end if
end for
min ((distance (answer, lenAnswer - 1, lenGuess, guess ) + 1),
(distance (answer, lenAnswer , lenGuess -1, guess ) + 1),
(distance (answer, lenAnswer - 1, lenGuess -1 , guess ) + 1))
Please specify what version of Turing you are using
4.1.1a |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|