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 / conways-game-of-life.wiki

156 lines · 2532 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 minus "-"
9text tgen "generation "
10text tdot "."
11text thash "#"
12global cur uchar 64
13global nxt uchar 64
14global dim ulong 2
15note emit writes every byte of a to stdout; a short write is retried, an error exits 1
16fn emit a view uchar * to void
17o = ulong 0
18while lt o len a bound 4096
19k = write 1 a o sub len a o
20if le k 0
21exit 1
22end
23o = add o ulong k
24end
25end
26note emitu writes n in decimal; 20 digits hold every ulong
27fn emitu n ulong to void
28d = new uchar 20 0
29i = ulong 20
30v = n
31while true bound 20
32i = sub i 1
33put d i uchar add rem v 10 48
34v = div v 10
35if eq v 0
36break
37end
38end
39emit part d i sub 20 i
40end
41note the board is dim[0] rows by dim[1] columns, row by row, with dead cells beyond the edges; a live
42note cell with 2 or 3 live neighbours lives on, a dead one with exactly 3 comes alive
43fn alive r long c long to ulong
44if or or lt r 0 ge r long get dim 0 or lt c 0 ge c long get dim 1
45ret 0
46end
47ret ulong get cur add mul ulong r get dim 1 ulong c
48end
49fn around r long c long to ulong
50n = ulong 0
51for a ulong 3
52for b ulong 3
53if or ne a 1 ne b 1
54n = add n alive sub add r long a 1 sub add c long b 1
55end
56end
57end
58ret n
59end
60fn step to void
61w = get dim 1
62for r ulong get dim 0
63for c ulong w
64n = around long r long c
65v = uchar 0
66if eq n 3
67v = 1
68end
69if and eq n 2 eq get cur add mul r w c 1
70v = 1
71end
72put nxt add mul r w c v
73end
74end
75for i ulong mul get dim 0 w
76put cur i get nxt i
77end
78end
79fn show g ulong to void
80emit tgen
81emitu g
82emit nl
83w = get dim 1
84for r ulong get dim 0
85for c ulong w
86if eq get cur add mul r w c 1
87emit thash
88else
89emit tdot
90end
91end
92emit nl
93end
94end
95fn run gens ulong to void
96for g ulong add gens 1
97show g
98if lt g gens
99step
100end
101end
102end
103fn main to int
104note a blinker on a 3 x 3 board for 3 generations
105put dim 0 3
106put dim 1 3
107for i ulong 9
108put cur i 0
109end
110put cur 3 1
111put cur 4 1
112put cur 5 1
113run 2
114emit nl
115note a glider on an 8 x 8 board; after 4 generations it has moved one cell down and right
116put dim 0 8
117put dim 1 8
118for i ulong 64
119put cur i 0
120end
121put cur 1 1
122put cur 10 1
123put cur 16 1
124put cur 17 1
125put cur 18 1
126run 4
127ret 0
128end
129</syntaxhighlight>
130{{out}}
131<pre>
132generation 0
133...
134###
135...
136generation 1
137.#.
138.#.
139.#.
140generation 2
141...
142###
143...
144
145generation 0
146.#......
147...
148........
149..#.....
150...#....
151.###....
152........
153........
154........
155........
156</pre>