interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / tasks / soundex / soundex.om

79 lines · 1449 bytes Raw Blame History
1note Rosetta Code task "Soundex": https://rosettacode.org/wiki/Soundex
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text sp " "
6note code of each letter a..z: 0 vowel (and y), 1..6 consonant groups, 7 h and w (ignored)
7text codes "01230127022455012623017202"
8text n0 "Robert"
9text n1 "Rupert"
10text n2 "Rubin"
11text n3 "Ashcraft"
12text n4 "Ashcroft"
13text n5 "Tymczak"
14text n6 "Pfister"
15text n7 "Honeyman"
16text n8 "Lee"
17text n9 "Gutierrez"
18text n10 "Jackson"
19text n11 "VanDeusen"
20note emit writes every byte of a to stdout; a short write is retried, an error exits 1
21fn emit a view uchar * to void
22o = ulong 0
23while lt o len a bound 4096
24k = write 1 a o sub len a o
25if le k 0
26exit 1
27end
28o = add o ulong k
29end
30end
31note American Soundex: keep the first letter, code the rest, drop repeats of the same code (h and w
32note do not separate them, vowels do), pad with zeros to four characters
33fn soundex a view uchar * to void
34o = new uchar 4 48
35c = get a 0
36if ge c 97
37c = sub c 32
38end
39put o 0 c
40prev = get codes sub c 65
41k = ulong 1
42for i ulong sub len a 1
43x = get a add i 1
44if ge x 97
45x = sub x 32
46end
47d = get codes sub x 65
48if eq d 48
49prev = d
50else
51if and ne d 55 ne d prev
52if lt k 4
53put o k d
54k = add k 1
55end
56prev = d
57end
58end
59end
60emit a
61emit sp
62emit o
63emit nl
64end
65fn main to int
66soundex n0
67soundex n1
68soundex n2
69soundex n3
70soundex n4
71soundex n5
72soundex n6
73soundex n7
74soundex n8
75soundex n9
76soundex n10
77soundex n11
78ret 0
79end