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 / count-how-many-vowels-and-consonants-occur-in-a-string.wiki

90 lines · 1638 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 tv "vowels "
8text tc ", consonants "
9text td "distinct vowels "
10text msg "Now is the time for all good men to come to the aid of their country."
11text vow "aeiou"
12note emit writes every byte of a to stdout; a short write is retried, an error exits 1
13fn emit a view uchar * to void
14o = ulong 0
15while lt o len a bound 4096
16k = write 1 a o sub len a o
17if le k 0
18exit 1
19end
20o = add o ulong k
21end
22end
23note emitu writes n in decimal; 20 digits hold every ulong
24fn emitu n ulong to void
25d = new uchar 20 0
26i = ulong 20
27v = n
28while true bound 20
29i = sub i 1
30put d i uchar add rem v 10 48
31v = div v 10
32if eq v 0
33break
34end
35end
36emit part d i sub 20 i
37end
38note letters are ASCII a..z either case; vowels a e i o u, the other letters are consonants
39fn main to int
40seen = new uchar 26 0
41v = ulong 0
42c = ulong 0
43for i ulong len msg
44x = get msg i
45if and ge x 65 le x 90
46x = add x 32
47end
48if and ge x 97 le x 122
49put seen sub x 97 1
50isv = false
51for j ulong len vow
52if eq x get vow j
53isv = true
54end
55end
56if isv
57v = add v 1
58else
59c = add c 1
60end
61end
62end
63emit tv
64emitu v
65emit tc
66emitu c
67emit nl
68dv = ulong 0
69dc = ulong 0
70for j ulong 26
71if eq get seen j 1
72dc = add dc 1
73end
74end
75for j ulong len vow
76dv = add dv ulong get seen sub get vow j 97
77end
78emit td
79emitu dv
80emit tc
81emitu sub dc dv
82emit nl
83ret 0
84end
85</syntaxhighlight>
86{{out}}
87<pre>
88vowels 22, consonants 31
89distinct vowels 5, consonants 13
90</pre>