-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.lua
More file actions
executable file
·60 lines (48 loc) · 1.19 KB
/
tools.lua
File metadata and controls
executable file
·60 lines (48 loc) · 1.19 KB
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
--- Assorted tools.
--@module tools
local M = {C = {}, max_choose = 55}
--- Generates a string representation of a table.
--@param table the table
--@return the string
function M:table_to_string(table)
local out = "{"
for key,value in pairs(table) do
local val_string = ''
if type(value) == 'table' then
val_string = self:table_to_string(value)
else
val_string = tostring(value)
end
out = out .. tostring(key) .. ":" .. val_string .. ", "
end
out = out .. "}"
return out
end
--- An arbitrarily large number used for clamping regrets.
--@return the number
function M:max_number()
return 999999
end
--- Initializes the choose table.
-- @local
function M:_init_choose()
for i = 0,self.max_choose do
for j = 0,self.max_choose do
self.C[i*self.max_choose + j] = 0
end
end
for i = 0,self.max_choose do
self.C[i*self.max_choose] = 1
self.C[i*self.max_choose + i] = 1
end
for i = 1,self.max_choose do
for j = 1,i do
self.C[i*self.max_choose + j] = self.C[(i-1)*self.max_choose + j-1] + self.C[(i-1)*self.max_choose + j]
end
end
end
M:_init_choose()
function M:choose(n, k)
return self.C[n*self.max_choose + k]
end
return M