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

111 lines · 2239 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 trule "rule "
10text tdot "."
11text thash "#"
12global cur uchar 32
13global nxt uchar 32
14note emit writes every byte of a to stdout; a short write is retried, an error exits 1
15fn emit a view uchar * to void
16o = ulong 0
17while lt o len a bound 4096
18k = write 1 a o sub len a o
19if le k 0
20exit 1
21end
22o = add o ulong k
23end
24end
25note emitu writes n in decimal; 20 digits hold every ulong
26fn emitu n ulong to void
27d = new uchar 20 0
28i = ulong 20
29v = n
30while true bound 20
31i = sub i 1
32put d i uchar add rem v 10 48
33v = div v 10
34if eq v 0
35break
36end
37end
38emit part d i sub 20 i
39end
40note 31 cells on a ring; a cell's next state is bit (4*left + 2*self + right) of the rule number
41fn line to void
42for i ulong 31
43if eq get cur i 1
44emit thash
45else
46emit tdot
47end
48end
49emit nl
50end
51fn step rule ulong to void
52for i ulong 31
53l = ulong get cur rem add i 30 31
54c = ulong get cur i
55r = ulong get cur rem add i 1 31
56k = add add mul l 4 mul c 2 r
57put nxt i uchar and shr rule k 1
58end
59for i ulong 31
60put cur i get nxt i
61end
62end
63fn run rule ulong to void
64emit trule
65emitu rule
66emit nl
67for i ulong 31
68put cur i 0
69end
70put cur 15 1
71for g ulong 16
72line
73step rule
74end
75end
76fn main to int
77run 90
78emit nl
79run 30
80emit nl
81run 110
82ret 0
83end
84</syntaxhighlight>
85{{out}}
86<pre>
87rule 90
88...............#...............
89..............#.#..............
90.............#...#.............
91............#.#.#.#............
92...........#.......#...........
93..........#.#.....#.#..........
94.........#...#...#...#.........
95........#.#.#.#.#.#.#.#........
96.......#...............#.......
97......#.#.............#.#......
98.....#...#...........#...#.....
99....#.#.#.#.........#.#.#.#....
100...#.......#.......#.......#...
101..#.#.....#.#.....#.#.....#.#..
102...
103.......#######.#...............
104......##.....###...............
105.....###....##.#...............
106....##.#...#####...............
107...#####..##...#...............
108..##...#.###..##...............
109.###..####.#.###...............
110##.#.##..#####.#...............
111</pre>