interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / drafts / rosettacode / soundex.wiki

97 lines · 1750 bytes Raw Blame History
1=={{header|Omegese}}==
2{{works with|omc|sha256 2c824805, aien-dev/omega-mv e5b32567, Linux AArch64}}
3Omega has no imports, so the small output helpers (<code>emit</code> and friends) are part of the program.
4<syntaxhighlight lang="text">
5om2
6text nl "\n"
7text sp " "
8note code of each letter a..z: 0 vowel (and y), 1..6 consonant groups, 7 h and w (ignored)
9text codes "01230127022455012623017202"
10text n0 "Robert"
11text n1 "Rupert"
12text n2 "Rubin"
13text n3 "Ashcraft"
14text n4 "Ashcroft"
15text n5 "Tymczak"
16text n6 "Pfister"
17text n7 "Honeyman"
18text n8 "Lee"
19text n9 "Gutierrez"
20text n10 "Jackson"
21text n11 "VanDeusen"
22note emit writes every byte of a to stdout; a short write is retried, an error exits 1
23fn emit a view uchar * to void
24o = ulong 0
25while lt o len a bound 4096
26k = write 1 a o sub len a o
27if le k 0
28exit 1
29end
30o = add o ulong k
31end
32end
33note American Soundex: keep the first letter, code the rest, drop repeats of the same code (h and w
34note do not separate them, vowels do), pad with zeros to four characters
35fn soundex a view uchar * to void
36o = new uchar 4 48
37c = get a 0
38if ge c 97
39c = sub c 32
40end
41put o 0 c
42prev = get codes sub c 65
43k = ulong 1
44for i ulong sub len a 1
45x = get a add i 1
46if ge x 97
47x = sub x 32
48end
49d = get codes sub x 65
50if eq d 48
51prev = d
52else
53if and ne d 55 ne d prev
54if lt k 4
55put o k d
56k = add k 1
57end
58prev = d
59end
60end
61end
62emit a
63emit sp
64emit o
65emit nl
66end
67fn main to int
68soundex n0
69soundex n1
70soundex n2
71soundex n3
72soundex n4
73soundex n5
74soundex n6
75soundex n7
76soundex n8
77soundex n9
78soundex n10
79soundex n11
80ret 0
81end
82</syntaxhighlight>
83{{out}}
84<pre>
85Robert R163
86Rupert R163
87Rubin R150
88Ashcraft A261
89Ashcroft A261
90Tymczak T522
91Pfister P236
92Honeyman H555
93Lee L000
94Gutierrez G362
95Jackson J250
96VanDeusen V532
97</pre>