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 / ludic-numbers.wiki

116 lines · 2517 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 first "first 25 ludic numbers:"
9text upto "ludic numbers <= 1000: "
10text tfrom "2000th to 2005th ludic numbers:"
11text trip "ludic triplets (x, x+2, x+6) below 250:"
12text lp " ("
13text cm ", "
14text rp ")"
15note the sieve runs on 2..21999; the 2005th ludic number, 21511, is below that limit, and every ludic number
16note found is final because removing every k-th survivor never touches the survivors in front of it
17global ls ulong 22000
18global lu ulong 22000
19global isl uchar 22000
20note emit writes every byte of a to stdout; a short write is retried, an error exits 1
21fn emit a view uchar * to void
22o = ulong 0
23while lt o len a bound 4096
24k = write 1 a o sub len a o
25if le k 0
26exit 1
27end
28o = add o ulong k
29end
30end
31note emitu writes n in decimal; 20 digits hold every ulong
32fn emitu n ulong to void
33d = new uchar 20 0
34i = ulong 20
35v = n
36while true bound 20
37i = sub i 1
38put d i uchar add rem v 10 48
39v = div v 10
40if eq v 0
41break
42end
43end
44emit part d i sub 20 i
45end
46note round: the first survivor k is ludic; it and every k-th survivor after it (positions 0, k, 2k, ...) go
47note bound: each round removes at least one survivor, so at most 21998 rounds over at most 21998 survivors
48fn main to int
49n = ulong 0
50for i ulong 21998
51put ls i add i 2
52n = add n 1
53end
54put lu 0 1
55put isl 1 1
56c = ulong 1
57while gt n 0 bound 22000
58k = get ls 0
59put lu c k
60put isl k 1
61c = add c 1
62m = ulong 0
63for i ulong n
64if ne rem i k 0
65put ls m get ls i
66m = add m 1
67end
68end
69n = m
70end
71emit first
72for i ulong 25
73emit sp
74emitu get lu i
75end
76emit nl
77emit upto
78m = ulong 0
79for i ulong c
80if le get lu i 1000
81m = add m 1
82end
83end
84emitu m
85emit nl
86emit tfrom
87for i ulong 6
88emit sp
89emitu get lu add 1999 i
90end
91emit nl
92emit trip
93for x ulong 244
94if eq get isl x 1
95if and eq get isl add x 2 1 eq get isl add x 6 1
96emit lp
97emitu x
98emit cm
99emitu add x 2
100emit cm
101emitu add x 6
102emit rp
103end
104end
105end
106emit nl
107ret 0
108end
109</syntaxhighlight>
110{{out}}
111<pre>
112first 25 ludic numbers: 1 2 3 5 7 11 13 17 23 25 29 37 41 43 47 53 61 67 71 77 83 89 91 97 107
113ludic numbers &lt;= 1000: 142
1142000th to 2005th ludic numbers: 21475 21481 21487 21493 21503 21511
115ludic triplets (x, x+2, x+6) below 250: (1, 3, 7) (5, 7, 11) (11, 13, 17) (23, 25, 29) (41, 43, 47) (173, 175, 179) (221, 223, 227) (233, 235, 239)
116</pre>