blob: fb503e3b342f7564a62789296311ee18e20ee591 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
// Evol functions.
// Author:
// Reid
// Description:
// Riddle enigma validator
//
// Arguments
// 0 PC answer
// 1 English correct answer
// 2 Translated correct answer
// TODO: levenshtein(), similar_text(), and maybe even soundex()
function script riddlevalidation {
.@answer$ = strtolower(getarg(0));
.@good$ = strtolower(getarg(1));
.@good_translated$ = strtolower(getarg(2));
.@size_answer = getstrlen(.@answer$);
.@size_good = getstrlen(.@good$);
.@size_good_translated = getstrlen(.@good_translated$);
.@max = max(.@size_answer, .@size_good_translated, .@size_good);
// Input is too long.
if (.@max > 20)
{
return false;
}
.@size_good *= 70;
.@size_good_translated *= 70;
for (.@i = 0; .@i < .@max; .@i++)
{
.@correct = 0;
.@correct_translated = 0;
for (.@k = .@k_translated = .@j = .@i; .@j < .@max; .@j++)
{
if (charat(.@answer$, .@j) == charat(.@good$, .@k))
{
.@correct++;
.@k++;
}
else
{
.@correct--;
}
if (charat(.@answer$, .@j) ==
charat(.@good_translated$, .@k_translated))
{
.@correct_translated++;
.@k_translated++;
}
else
{
.@correct_translated--;
}
}
// if 70% of the word is correct
.@correct *= 100;
.@correct_translated *= 100;
if (.@correct >= .@size_good ||
.@correct_translated >= .@size_good_translated)
{
return true;
}
}
return false;
}
|