-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExamples.lua
executable file
·52 lines (46 loc) · 992 Bytes
/
Examples.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
#!/usr/bin/env lua
local Dice = require'Dice'
local example_inputs = {
'1d6',
'1d4',
'1d3x3',
'2d6',
'2d3',
'1d6+1',
'1d6-1d4',
'5d3+1d2-1',
'1d10-1d7+8',
'0',
'-1',
'1d6-1d6',
'2 + 3d2 + 2d6',
'2+3d2+2d6',
'0d1',
'0d11',
'1-6',
'1-4',
'1-3x2',
'4-8',
}
local function print_distribution(string, dice)
print('distribution:', string)
print('minimum: ', dice:minimum())
print('average: ', dice:average())
print('maximum: ', dice:maximum())
print('range: ', dice:range())
print('variance: ', dice:variance())
end
local function main()
for i, input in ipairs(example_inputs) do
if i ~= 1 then
print()
end
local dice = Dice.parse(input)
print_distribution(input, dice)
end
end
-- If this module is run without arguments, run the main function.
if ... == nil then
main()
end
return main