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 / elementary-cellular-automaton / elementary-cellular-automaton.om

81 lines · 1421 bytes Raw Blame History
1note Rosetta Code task "Elementary cellular automaton": https://rosettacode.org/wiki/Elementary_cellular_automaton
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text sp " "
6text minus "-"
7text trule "rule "
8text tdot "."
9text thash "#"
10global cur uchar 32
11global nxt uchar 32
12note emit writes every byte of a to stdout; a short write is retried, an error exits 1
13fn emit a view uchar * to void
14o = ulong 0
15while lt o len a bound 4096
16k = write 1 a o sub len a o
17if le k 0
18exit 1
19end
20o = add o ulong k
21end
22end
23note emitu writes n in decimal; 20 digits hold every ulong
24fn emitu n ulong to void
25d = new uchar 20 0
26i = ulong 20
27v = n
28while true bound 20
29i = sub i 1
30put d i uchar add rem v 10 48
31v = div v 10
32if eq v 0
33break
34end
35end
36emit part d i sub 20 i
37end
38note 31 cells on a ring; a cell's next state is bit (4*left + 2*self + right) of the rule number
39fn line to void
40for i ulong 31
41if eq get cur i 1
42emit thash
43else
44emit tdot
45end
46end
47emit nl
48end
49fn step rule ulong to void
50for i ulong 31
51l = ulong get cur rem add i 30 31
52c = ulong get cur i
53r = ulong get cur rem add i 1 31
54k = add add mul l 4 mul c 2 r
55put nxt i uchar and shr rule k 1
56end
57for i ulong 31
58put cur i get nxt i
59end
60end
61fn run rule ulong to void
62emit trule
63emitu rule
64emit nl
65for i ulong 31
66put cur i 0
67end
68put cur 15 1
69for g ulong 16
70line
71step rule
72end
73end
74fn main to int
75run 90
76emit nl
77run 30
78emit nl
79run 110
80ret 0
81end