forked from bext-lang/b
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrule110.b
More file actions
49 lines (41 loc) · 789 Bytes
/
rule110.b
File metadata and controls
49 lines (41 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// -*- mode: simpc -*-
word;
display(base, n) {
extrn printf;
auto i;
i = 0;
while (i < n) {
if (base[i]) printf("#"); else printf(".");
i += 1;
}
printf("\n");
}
next(base, n) {
auto i, state;
state = base[0] | base[1] << 1;
i = 2;
while (i < n) {
state <<= 1;
state |= base[i];
state &= 7;
base[i - 1] = (110>>state)&1;
i += 1;
}
}
main() {
extrn malloc, memset;
auto base, n;
word = &0[1]; /* trick to obtain the word size */
n = 100;
base = malloc(word*n);
memset(base, 0, word*n);
base[n - 2] = 1;
display(base, n);
auto i;
i = 0;
while (i < n - 3) {
next(base, n);
display(base, n);
i += 1;
}
}