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 / wireworld.wiki

133 lines · 2306 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 tstart "tH.........|. . | ... |. . |Ht.. ......"
10text tgen "generation "
11global cur uchar 55
12global nxt uchar 55
13note emit writes every byte of a to stdout; a short write is retried, an error exits 1
14fn emit a view uchar * to void
15o = ulong 0
16while lt o len a bound 4096
17k = write 1 a o sub len a o
18if le k 0
19exit 1
20end
21o = add o ulong k
22end
23end
24note emitu writes n in decimal; 20 digits hold every ulong
25fn emitu n ulong to void
26d = new uchar 20 0
27i = ulong 20
28v = n
29while true bound 20
30i = sub i 1
31put d i uchar add rem v 10 48
32v = div v 10
33if eq v 0
34break
35end
36end
37emit part d i sub 20 i
38end
39note emitb writes the single byte c
40fn emitb c ulong to void
41d = new uchar 1 0
42put d 0 uchar c
43emit d
44end
45note the 5 x 11 board from the task: H electron head, t tail, . conductor, space empty; a head becomes a
46note tail, a tail a conductor, and a conductor a head when 1 or 2 of its 8 neighbours are heads
47fn heads r long c long to ulong
48n = ulong 0
49for a ulong 3
50for b ulong 3
51y = sub add r long a 1
52x = sub add c long b 1
53if and and ge y 0 lt y 5 and ge x 0 lt x 11
54if eq get cur add mul ulong y 11 ulong x 72
55n = add n 1
56end
57end
58end
59end
60ret n
61end
62fn rule k ulong n ulong to uchar
63v = get cur k
64if eq v 72
65ret 116
66end
67if eq v 116
68ret 46
69end
70if and eq v 46 or eq n 1 eq n 2
71ret 72
72end
73ret v
74end
75fn step to void
76for r ulong 5
77for c ulong 11
78k = add mul r 11 c
79put nxt k rule k heads long r long c
80end
81end
82for i ulong 55
83put cur i get nxt i
84end
85end
86fn main to int
87for r ulong 5
88for c ulong 11
89put cur add mul r 11 c get tstart add mul r 12 c
90end
91end
92for g ulong 10
93emit tgen
94emitu g
95emit nl
96for i ulong 55
97emitb ulong get cur i
98if eq rem i 11 10
99emit nl
100end
101end
102step
103end
104ret 0
105end
106</syntaxhighlight>
107{{out}}
108<pre>
109generation 0
110tH.........
111. .
112 ...
113. .
114Ht.. ......
115generation 1
116.tH........
117H .
118 ...
119H .
120t... ......
121generation 2
122H.tH.......
123t .
124...
125t .
126.H.t ......
127generation 9
128tH.tH.tH.tH
129. H
130 ...
131. .
132HtH. ......
133</pre>