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-occurrences-of-a-substring.wiki

69 lines · 1267 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 h1 "the three truths"
8text n1 "th"
9text h2 "ababababab"
10text n2 "abab"
11note emit writes every byte of a to stdout; a short write is retried, an error exits 1
12fn emit a view uchar * to void
13o = ulong 0
14while lt o len a bound 4096
15k = write 1 a o sub len a o
16if le k 0
17exit 1
18end
19o = add o ulong k
20end
21end
22note emitu writes n in decimal; 20 digits hold every ulong
23fn emitu n ulong to void
24d = new uchar 20 0
25i = ulong 20
26v = n
27while true bound 20
28i = sub i 1
29put d i uchar add rem v 10 48
30v = div v 10
31if eq v 0
32break
33end
34end
35emit part d i sub 20 i
36end
37note count scans left to right and skips past each match, so matches never overlap
38fn count s view uchar * t view uchar * to ulong
39c = ulong 0
40i = ulong 0
41while le add i len t len s bound 4096
42m = true
43for j ulong len t
44if ne get s add i j get t j
45m = false
46end
47end
48if m
49c = add c 1
50i = add i len t
51else
52i = add i 1
53end
54end
55ret c
56end
57fn main to int
58emitu count h1 n1
59emit nl
60emitu count h2 n2
61emit nl
62ret 0
63end
64</syntaxhighlight>
65{{out}}
66<pre>
673
682
69</pre>