interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / tasks / sum-and-product-of-an-array / sum-and-product-of-an-array.om

51 lines · 920 bytes Raw Blame History
1note Rosetta Code task "Sum and product of an array": https://rosettacode.org/wiki/Sum_and_product_of_an_array
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text tsum "sum "
6text tprod "product "
7note emit writes every byte of a to stdout; a short write is retried, an error exits 1
8fn emit a view uchar * to void
9o = ulong 0
10while lt o len a bound 4096
11k = write 1 a o sub len a o
12if le k 0
13exit 1
14end
15o = add o ulong k
16end
17end
18note emitu writes n in decimal; 20 digits hold every ulong
19fn emitu n ulong to void
20d = new uchar 20 0
21i = ulong 20
22v = n
23while true bound 20
24i = sub i 1
25put d i uchar add rem v 10 48
26v = div v 10
27if eq v 0
28break
29end
30end
31emit part d i sub 20 i
32end
33fn main to int
34a = new ulong 10 0
35for i ulong 10
36put a i add i 1
37end
38s = ulong 0
39p = ulong 1
40for i ulong 10
41s = add s get a i
42p = mul p get a i
43end
44emit tsum
45emitu s
46emit nl
47emit tprod
48emitu p
49emit nl
50ret 0
51end