interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / si / rosetta / tasks / count-how-many-vowels-and-consonants-occur-in-a-string / count-how-many-vowels-and-consonants-occur-in-a-string.om

82 lines · 1528 bytes Raw Blame History
1note Rosetta Code task "Count how many vowels and consonants occur in a string": https://rosettacode.org/wiki/Count_how_many_vowels_and_consonants_occur_in_a_string
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text tv "vowels "
6text tc ", consonants "
7text td "distinct vowels "
8text msg "Now is the time for all good men to come to the aid of their country."
9text vow "aeiou"
10note emit writes every byte of a to stdout; a short write is retried, an error exits 1
11fn emit a view uchar * to void
12o = ulong 0
13while lt o len a bound 4096
14k = write 1 a o sub len a o
15if le k 0
16exit 1
17end
18o = add o ulong k
19end
20end
21note emitu writes n in decimal; 20 digits hold every ulong
22fn emitu n ulong to void
23d = new uchar 20 0
24i = ulong 20
25v = n
26while true bound 20
27i = sub i 1
28put d i uchar add rem v 10 48
29v = div v 10
30if eq v 0
31break
32end
33end
34emit part d i sub 20 i
35end
36note letters are ASCII a..z either case; vowels a e i o u, the other letters are consonants
37fn main to int
38seen = new uchar 26 0
39v = ulong 0
40c = ulong 0
41for i ulong len msg
42x = get msg i
43if and ge x 65 le x 90
44x = add x 32
45end
46if and ge x 97 le x 122
47put seen sub x 97 1
48isv = false
49for j ulong len vow
50if eq x get vow j
51isv = true
52end
53end
54if isv
55v = add v 1
56else
57c = add c 1
58end
59end
60end
61emit tv
62emitu v
63emit tc
64emitu c
65emit nl
66dv = ulong 0
67dc = ulong 0
68for j ulong 26
69if eq get seen j 1
70dc = add dc 1
71end
72end
73for j ulong len vow
74dv = add dv ulong get seen sub get vow j 97
75end
76emit td
77emitu dv
78emit tc
79emitu sub dc dv
80emit nl
81ret 0
82end