interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / si / rosetta / tasks / van-eck-sequence / van-eck-sequence.om

60 lines · 1214 bytes Raw Blame History
1note Rosetta Code task "Van Eck sequence": https://rosettacode.org/wiki/Van_Eck_sequence
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text sp " "
6text first "terms 1 to 10:"
7text last "terms 991 to 1000:"
8note emit writes every byte of a to stdout; a short write is retried, an error exits 1
9fn emit a view uchar * to void
10o = ulong 0
11while lt o len a bound 4096
12k = write 1 a o sub len a o
13if le k 0
14exit 1
15end
16o = add o ulong k
17end
18end
19note emitu writes n in decimal; 20 digits hold every ulong
20fn emitu n ulong to void
21d = new uchar 20 0
22i = ulong 20
23v = n
24while true bound 20
25i = sub i 1
26put d i uchar add rem v 10 48
27v = div v 10
28if eq v 0
29break
30end
31end
32emit part d i sub 20 i
33end
34note a(0) = 0; a(n+1) = n - m where m < n is the last earlier index with a(m) = a(n), else 0
35note ls v is one more than the last index holding v (0: not seen); every term is below 1000, its index
36fn main to int
37a = new ulong 1000 0
38ls = new ulong 1000 0
39for n ulong 999
40v = get a n
41w = get ls v
42if gt w 0
43put a add n 1 sub n sub w 1
44end
45put ls v add n 1
46end
47emit first
48for i ulong 10
49emit sp
50emitu get a i
51end
52emit nl
53emit last
54for i ulong 10
55emit sp
56emitu get a add 990 i
57end
58emit nl
59ret 0
60end