-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrule110.pyre
85 lines (72 loc) · 1.56 KB
/
rule110.pyre
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import "std"
procedure print_num num -- in
' ' putchar
if num 1 = do
'*' putchar
else
' ' putchar
end
end
procedure rule110 lcr -- res in
if lcr 000 = do 0 !res # 000 -> 0
elif lcr 001 = do 1 !res # 001 -> 1
elif lcr 010 = do 1 !res # 010 -> 1
elif lcr 011 = do 1 !res # 011 -> 1
elif lcr 100 = do 0 !res # 100 -> 0
elif lcr 101 = do 1 !res # 101 -> 1
elif lcr 110 = do 1 !res # 110 -> 1
elif lcr 111 = do 0 !res # 111 -> 0
end
end
procedure to_dec a b c -- res in
a 100 *
b 10 *
c + +
!res
end
procedure get_110 position -- res in
position position position
where i j k in
i--
k++
memory[i] !i
memory[j] !j
memory[k] !k
end
to_dec !res
end
# Constants
define LENGTH 40
define MAX_BUFFER_SIZE 500
define LINES 40
procedure print_line -- in
1
where c in
while c LENGTH < do
memory:uint8[c] print_num
c++
end
end drop
'\n' putchar
end
procedure main -- in
"Let's do some rule 110 stuff \n" print
# (0, 0, MAX_BUFFER_SIZE 2 *) set_mem
0 0 MAX_BUFFER_SIZE 2 * set_mem
1 !memory:uint8[LENGTH 1 -]
print_line
1 1
where line cell in
while line LINES < do
1 !cell
while cell LENGTH < do
cell get_110 rule110 !memory:uint8[cell MAX_BUFFER_SIZE +]
cell++
end
0 MAX_BUFFER_SIZE LENGTH copy_mem
print_line
line++
end
end
drop drop
end