September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
5
Task/Soundex/Factor/soundex.factor
Normal file
5
Task/Soundex/Factor/soundex.factor
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
USE: soundex
|
||||
"soundex" soundex ! S532
|
||||
"example" soundex ! E251
|
||||
"ciondecks" soundex ! C532
|
||||
"ekzampul" soundex ! E251
|
||||
62
Task/Soundex/Objeck/soundex.objeck
Normal file
62
Task/Soundex/Objeck/soundex.objeck
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
class SoundEx {
|
||||
function : Main(args : String[]) ~ Nil {
|
||||
SoundEx("Soundex")->PrintLine();
|
||||
SoundEx("Example")->PrintLine();
|
||||
SoundEx("Sownteks")->PrintLine();
|
||||
SoundEx("Ekzampul")->PrintLine();
|
||||
}
|
||||
|
||||
function : SoundEx(s : String) ~ String {
|
||||
input := s->ToUpper()->Get(0);
|
||||
code := input->ToString();
|
||||
previous := GetCode(input);
|
||||
|
||||
for(i := 1; i < s->Size(); i += 1;) {
|
||||
current := GetCode(s->ToUpper()->Get(i));
|
||||
if(current->Size() > 0 & <>current->Equals(previous)) {
|
||||
code += current;
|
||||
};
|
||||
previous := current;
|
||||
};
|
||||
|
||||
soundex := String->New(code);
|
||||
soundex += "0000";
|
||||
return soundex->SubString(4);
|
||||
}
|
||||
|
||||
function : GetCode(c : Char) ~ String {
|
||||
select(c) {
|
||||
label 'B': label 'F':
|
||||
label 'P': label 'V': {
|
||||
return "1";
|
||||
}
|
||||
|
||||
label 'C': label 'G':
|
||||
label 'J': label 'K':
|
||||
label 'Q': label 'S':
|
||||
label 'X': label 'Z': {
|
||||
return "2";
|
||||
}
|
||||
|
||||
label 'D': label 'T': {
|
||||
return "3";
|
||||
}
|
||||
|
||||
label 'L': {
|
||||
return "4";
|
||||
}
|
||||
|
||||
label 'M': label 'N': {
|
||||
return "5";
|
||||
}
|
||||
|
||||
label 'R': {
|
||||
return "6";
|
||||
}
|
||||
|
||||
other: {
|
||||
return "";
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
79
Task/Soundex/Phix/soundex.phix
Normal file
79
Task/Soundex/Phix/soundex.phix
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
constant soundex_alphabet = "0123012#02245501262301#202"
|
||||
-- ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
||||
|
||||
function soundex(string name)
|
||||
string res = "0000"
|
||||
integer rdx = 1, ch, this, prev
|
||||
for i=1 to length(name) do
|
||||
ch = upper(name[i])
|
||||
if ch>='A' and ch<='Z' then
|
||||
this = soundex_alphabet[ch-'A'+1]
|
||||
if rdx=1 then
|
||||
res[1] = ch
|
||||
rdx = 2
|
||||
prev = this
|
||||
elsif this!='#' then
|
||||
if this!='0' and this!=prev then
|
||||
res[rdx] = this
|
||||
if rdx=4 then exit end if
|
||||
rdx += 1
|
||||
end if
|
||||
prev = this
|
||||
end if
|
||||
end if
|
||||
end for
|
||||
return res
|
||||
end function
|
||||
|
||||
constant tests = {
|
||||
{"Ashcraft", "A261"}, -- not "A226"
|
||||
{"Ashcroft", "A261"}, -- not "A226"
|
||||
{"Ashkrofd", "A261"}, -- not "A226"
|
||||
{"Burroughs", "B620"},
|
||||
{"Burrows", "B620"},
|
||||
{"ciondecks", "C532"},
|
||||
{"Example", "E251"},
|
||||
{"Ekzampul", "E251"},
|
||||
{"Ellery", "E460"},
|
||||
{"Euler", "E460"},
|
||||
{"Gauss", "G200"},
|
||||
{"Ghosh", "G200"},
|
||||
{"Gutierrez", "G362"},
|
||||
{"He", "H000"},
|
||||
{"Heilbronn", "H416"},
|
||||
{"Hilbert", "H416"},
|
||||
{"Honeyman", "H555"}, -- not "H500"
|
||||
{"Jackson", "J250"},
|
||||
{"Kant", "K530"},
|
||||
{"Knuth", "K530"},
|
||||
{"Lee", "L000"},
|
||||
{"Ladd", "L300"},
|
||||
{"Lloyd", "L300"},
|
||||
{"Lissajous", "L222"},
|
||||
{"Lukasiewicz", "L222"},
|
||||
{"Moses", "M220"},
|
||||
{"O'Hara", "O600"},
|
||||
{"Pfister", "P236"}, -- not "P123"
|
||||
{"Robert", "R163"},
|
||||
{"Rupert", "R163"},
|
||||
{"Rubin", "R150"},
|
||||
{"r~@sum~@", "R250"},
|
||||
{"Soundex", "S532"},
|
||||
{"Sownteks", "S532"},
|
||||
{"Tymczak", "T522"}, -- not "T520"
|
||||
{"VanDeusen", "V532"},
|
||||
{"Washington", "W252"},
|
||||
{"Wheaton", "W350"},
|
||||
{"Weeton", "W350"},
|
||||
{"", "0000"},
|
||||
{" ", "0000"},
|
||||
{"12346", "0000"},
|
||||
{"aaa a", "A000"}
|
||||
}
|
||||
|
||||
for i=1 to length(tests) do
|
||||
string {name,expected} = tests[i],
|
||||
res = soundex(name),
|
||||
ok = iff(res=expected?"":"*** ERROR ***")
|
||||
printf(1,"%-12s -> %s %s\n",{name,res,ok})
|
||||
end for
|
||||
Loading…
Add table
Add a link
Reference in a new issue