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 / ethiopian-multiplication.wiki

87 lines · 1510 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 sp " "
8text kept " KEPT\n"
9text struck " STRUCK\n"
10text tx " x "
11text teq " = "
12note emit writes every byte of a to stdout; a short write is retried, an error exits 1
13fn emit a view uchar * to void
14o = ulong 0
15while lt o len a bound 4096
16k = write 1 a o sub len a o
17if le k 0
18exit 1
19end
20o = add o ulong k
21end
22end
23note emitu writes n in decimal; 20 digits hold every ulong
24fn emitu n ulong to void
25d = new uchar 20 0
26i = ulong 20
27v = n
28while true bound 20
29i = sub i 1
30put d i uchar add rem v 10 48
31v = div v 10
32if eq v 0
33break
34end
35end
36emit part d i sub 20 i
37end
38fn halve n ulong to ulong
39ret shr n 1
40end
41fn double n ulong to ulong
42ret shl n 1
43end
44fn iseven n ulong to bool
45ret eq and n 1 0
46end
47note left column halves to 1, right column doubles; rows with an even left number are struck out and
48note the kept right numbers add up to the product
49fn ethiop a ulong b ulong to ulong
50s = ulong 0
51l = a
52r = b
53while ge l 1 bound 64
54emitu l
55emit sp
56emitu r
57if iseven l
58emit struck
59else
60emit kept
61s = add s r
62end
63l = halve l
64r = double r
65end
66ret s
67end
68fn main to int
69p = ethiop 17 34
70emitu 17
71emit tx
72emitu 34
73emit teq
74emitu p
75emit nl
76ret 0
77end
78</syntaxhighlight>
79{{out}}
80<pre>
8117 34 KEPT
828 68 STRUCK
834 136 STRUCK
842 272 STRUCK
851 544 KEPT
8617 x 34 = 578
87</pre>