Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,35 @@
let c2d = function
| 'B' | 'F' | 'P' | 'V' -> "1"
| 'C' | 'G' | 'J' | 'K' | 'Q' | 'S' | 'X' | 'Z' -> "2"
| 'D' | 'T' -> "3"
| 'L' -> "4"
| 'M' | 'N' -> "5"
| 'R' -> "6"
| _ -> ""
let rec dbl acc = function
| [] -> (List.rev acc)
| [c] -> List.rev(c::acc)
| c1::(c2::_ as tl) ->
if c1 = c2
then dbl acc tl
else dbl (c1::acc) tl
let pad s =
match String.length s with
| 0 -> s ^ "000"
| 1 -> s ^ "00"
| 2 -> s ^ "0"
| 3 -> s
| _ -> String.sub s 0 3
let soundex_aux rem =
pad(String.concat "" (dbl [] (List.map c2d rem)))
let soundex s =
let s = String.uppercase s in
let cl = ref [] in
String.iter (fun c -> cl := c :: !cl) s;
match dbl [] (List.rev !cl) with
| c::rem -> (String.make 1 c) ^ (soundex_aux rem)
| [] -> invalid_arg "soundex"

View file

@ -0,0 +1,31 @@
let tests = [
"Soundex", "S532";
"Example", "E251";
"Sownteks", "S532";
"Ekzampul", "E251";
"Euler", "E460";
"Gauss", "G200";
"Hilbert", "H416";
"Knuth", "K530";
"Lloyd", "L300";
"Lukasiewicz", "L222";
"Ellery", "E460";
"Ghosh", "G200";
"Heilbronn", "H416";
"Kant", "K530";
"Ladd", "L300";
"Lissajous", "L222";
"Wheaton", "W350";
"Ashcraft", "A226";
"Burroughs", "B622";
"Burrows", "B620";
"O'Hara", "O600";
]
let () =
print_endline " Word \t Code Found Status";
List.iter (fun (word, code1) ->
let code2 = soundex word in
let status = if code1 = code2 then "OK " else "Arg" in
Printf.printf " \"%s\" \t %s %s %s\n" word code1 code2 status
) tests