-
Notifications
You must be signed in to change notification settings - Fork 0
/
chains.lua
124 lines (99 loc) · 2.22 KB
/
chains.lua
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
malgorithm{ -- takes "aaa*aa" and returns "aaaaaa" (unary multiplication)
name = "mult",
{["Ba"] = "aB"},
{["Aa"] = "aBA"},
{["A"] = ""},
{["a*"] = "*A"},
{["*a"] = "*"},
{["*"] = ""},
{["B"] = "a"},
}
malgorithm{ -- takes "aaaa|aa" and returns gcd(aaaa, aa) (unary gcd)
name = "gcd",
{["aA"] = "Aa"},
{["a|a"] = "A|"},
{["a|"] = "|B"},
{["B"] = "a"},
{["A"] = "C"},
{["C"] = "a"},
{["|"] = ""}
}
malgorithm{ -- takes "aaa-aa" and returns "a" (unary difference)
name = "diff",
{["a-a"] = "-"},
{["a-"] = "a", terminating = true},
{["-a"] = "-a", terminating = true},
{["-"] = "", terminating = true}
}
malgorithm{ -- takes "aaa+aa" and returns "aaaaa" (unary addition)
name = "sum",
{["a+a"] = "aa"},
}
malgorithm{ -- takes "a" and never halts
name = "nohalt",
{["a"] = "a"}
}
malgorithm{ -- converts "0101" to "aaaaa" (binary to unary conversion)
name = "toun",
{["1"] = "0a"},
{["a0"] = "0aa"},
{["0"] = ""}
}
malgorithm{ -- converts "0111*011" to "0111111" (unary like with first zero)
name = "mult2",
{["^1"] = "1#^"},
{["^"] = ""},
{["#1"] = "1#"},
{["1*0"] = "*0^"},
{["00"] = "0"},
{["*0"] = "0*"},
{["*1"] = "*"},
{["*#"] = "1*"},
{["*"] = "", terminating = true}
}
malgorithm{ -- doubles string "aaa" to "aaaaaa"
name = "double",
{["*a"] = "aa*"},
{["*"] = "", terminating = true},
{["a"] = "*a"}
}
malgorithm{ -- takes "aaaaa/aa" and returns "aaRa" (unary division with remainder)
name = "div",
{["*A"] = "Pc*"}, -- 4
{["cP"] = "Pc"}, -- 5
{["*"] = ""}, -- 6
{["cc"] = "c"}, -- 7
{["c"] = "x"}, -- 8
{["P"] = "a"}, -- 9
{["Aa"] = "aA"}, -- 2
{["a/a"] = "/A"}, -- 1
{["/aA"] = "/ar"}, -- 10
{["rA"] = "Ar"}, -- 11
{["/a"] = "/"}, -- 12
{["A"] = "*A"}, -- 3
{["rx"] = "xr"}, -- 13
{["xr"] = "xRr"}, -- 14
{["/r"] = "Rr"}, -- 15
{["/"] = ""}, -- 16
{["r"] = "a"}, -- 17
{["x"] = "a"}, -- 18
}
--[[
malgorithm{ -- takes "2^a...a-3^a...a" and returns "aa...aaa"
name = "2^x-3^y",
{["Ba"] = "aB"},
{["Aa"] = "aBA"},
{["A"] = ""},
{["a*"] = "*A"},
{["*a"] = "*"},
{["*"] = ""},
{["B"] = "a"},
{["2^a"] = "aa*2^"},
{["*2^"] = ""},
{["3^a"] = "aaa*3^"},
{["*3^"] = ""},
{["a-a"] = "-"},
{["a-"] = "a", terminating = true},
{["-a"] = "-a", terminating = true}
}
--]]