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 / palindrome-detection.wiki

86 lines · 1658 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 tq "\""
8text tex "\" exact "
9text tin " inexact "
10text tyes "yes"
11text tno "no"
12text p1 "rotor"
13text p2 "level"
14text p3 "A man, a plan, a canal: Panama!"
15text p4 "In girum imus nocte et consumimur igni"
16text p5 "hello"
17note emit writes every byte of a to stdout; a short write is retried, an error exits 1
18fn emit a view uchar * to void
19o = ulong 0
20while lt o len a bound 4096
21k = write 1 a o sub len a o
22if le k 0
23exit 1
24end
25o = add o ulong k
26end
27end
28fn emitb b bool to void
29if b
30emit tyes
31else
32emit tno
33end
34end
35note exact compares bytes from both ends
36fn exact a view uchar * to bool
37n = len a
38for i ulong div n 2
39if ne get a i get a sub sub n 1 i
40ret false
41end
42end
43ret true
44end
45note inexact keeps letters only, lower-cased, then compares (strings up to 256 bytes)
46fn inexact a view uchar * to bool
47b = new uchar 256 0
48n = ulong 0
49for i ulong len a
50c = get a i
51if and ge c 65 le c 90
52c = add c 32
53end
54if and ge c 97 le c 122
55put b n c
56n = add n 1
57end
58end
59ret exact part b 0 n
60end
61fn show a view uchar * to void
62emit tq
63emit a
64emit tex
65emitb exact a
66emit tin
67emitb inexact a
68emit nl
69end
70fn main to int
71show p1
72show p2
73show p3
74show p4
75show p5
76ret 0
77end
78</syntaxhighlight>
79{{out}}
80<pre>
81"rotor" exact yes inexact yes
82"level" exact yes inexact yes
83"A man, a plan, a canal: Panama!" exact no inexact yes
84"In girum imus nocte et consumimur igni" exact no inexact yes
85"hello" exact no inexact no
86</pre>