Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them.
Page: /drakestapleton/omega-rosetta/blob/main/drafts/rosettacode/jewels-and-stones.wiki
# omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
Sign in to star 0 stars 0 watching
About Files History Releases Proposed changes Issues For developers
branch `main` Branches Tags History
`omega-rosetta / drafts / rosettacode / jewels-and-stones.wiki`
69 lines ยท 1253 bytes Raw Blame History
1 =={{header|Omegese}}==
2 {{works with|omc|sha256 `2c824805`, aien-dev/omega-mv `e5b32567`, Linux AArch64}}
3 Omega has no imports, so the small output helpers (emit and friends) are part of the program.
4
5 om2
6 text nl "\n"
7 text sp " "
8 text s1 "aAAbbbb"
9 text j1 "aA"
10 text s2 "ZZ"
11 text j2 "z"
12 note emit writes every byte of a to stdout; a short write is retried, an error exits 1
13 fn emit a view uchar * to void
14 o = ulong 0
15 while lt o len a bound 4096
16 k = write 1 a o sub len a o
17 if le k 0
18 exit 1
19 end
20 o = add o ulong k
21 end
22 end
23 note emitu writes n in decimal; 20 digits hold every ulong
24 fn emitu n ulong to void
25 d = new uchar 20 0
26 i = ulong 20
27 v = n
28 while true bound 20
29 i = sub i 1
30 put d i uchar add rem v 10 48
31 v = div v 10
32 if eq v 0
33 break
34 end
35 end
36 emit part d i sub 20 i
37 end
38 note count the stones (bytes of s) that are jewels (occur in j); case matters
39 fn jewels s view uchar * j view uchar * to ulong
40 n = ulong 0
41 for i ulong len s
42 for k ulong len j
43 if eq get s i get j k
44 n = add n 1
45 break
46 end
47 end
48 end
49 ret n
50 end
51 fn show s view uchar * j view uchar * to void
52 emit s
53 emit sp
54 emit j
55 emit sp
56 emitu jewels s j
57 emit nl
58 end
59 fn main to int
60 show s1 j1
61 show s2 j2
62 ret 0
63 end
64
65 {{out}}
66
67 aAAbbbb aA 3
68 ZZ z 0
69