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 / jewels-and-stones / jewels-and-stones.om

61 lines · 1107 bytes Raw Blame History
1note Rosetta Code task "Jewels and stones": https://rosettacode.org/wiki/Jewels_and_stones
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text sp " "
6text s1 "aAAbbbb"
7text j1 "aA"
8text s2 "ZZ"
9text j2 "z"
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 count the stones (bytes of s) that are jewels (occur in j); case matters
37fn jewels s view uchar * j view uchar * to ulong
38n = ulong 0
39for i ulong len s
40for k ulong len j
41if eq get s i get j k
42n = add n 1
43break
44end
45end
46end
47ret n
48end
49fn show s view uchar * j view uchar * to void
50emit s
51emit sp
52emit j
53emit sp
54emitu jewels s j
55emit nl
56end
57fn main to int
58show s1 j1
59show s2 j2
60ret 0
61end