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/recamans-sequence.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 / recamans-sequence.wiki`
92 lines ยท 1811 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 first "first 15 terms:"
9 text dup "first term already seen: a("
10 text eqs ") = "
11 text cov "terms a(0)..a(n) first contain every integer 0..1000 at n = "
12 note sn v is 1 once v has appeared; the oracle's run shows no term before 0..1000 is covered exceeds `1942300`
13 global sn uchar `1942301`
14 note emit writes every byte of a to stdout; a short write is retried, an error exits 1
15 fn emit a view uchar * to void
16 o = ulong 0
17 while lt o len a bound 4096
18 k = write 1 a o sub len a o
19 if le k 0
20 exit 1
21 end
22 o = add o ulong k
23 end
24 end
25 note emitu writes n in decimal; 20 digits hold every ulong
26 fn emitu n ulong to void
27 d = new uchar 20 0
28 i = ulong 20
29 v = n
30 while true bound 20
31 i = sub i 1
32 put d i uchar add rem v 10 48
33 v = div v 10
34 if eq v 0
35 break
36 end
37 end
38 emit part d i sub 20 i
39 end
40 note a(0) = 0; a(n) = a(n-1) - n if that is positive and new, else a(n-1) + n
41 note bound: the cover is complete at n = 328002, below the 999999 loop bound
42 fn main to int
43 emit first
44 emit sp
45 emitu 0
46 put sn 0 1
47 a = ulong 0
48 n = ulong 0
49 d = ulong 0
50 c = ulong 1
51 while lt c 1001 bound 999999
52 n = add n 1
53 nw = add a n
54 if gt a n
55 if eq get sn sub a n 0
56 nw = sub a n
57 end
58 end
59 a = nw
60 if eq get sn a 0
61 if le a 1000
62 c = add c 1
63 end
64 else
65 if eq d 0
66 d = n
67 emit nl
68 emit dup
69 emitu n
70 emit eqs
71 emitu a
72 emit nl
73 end
74 end
75 put sn a 1
76 if lt n 15
77 emit sp
78 emitu a
79 end
80 end
81 emit cov
82 emitu n
83 emit nl
84 ret 0
85 end
86
87 {{out}}
88
89 first 15 terms: 0 1 3 6 2 7 13 20 12 21 11 22 10 23 9
90 first term already seen: a(24) = 42
91 terms a(0)..a(n) first contain every integer 0..1000 at n = 328002
92