First commit
This commit is contained in:
25
exercises/ch03/ex3_6.lua
Normal file
25
exercises/ch03/ex3_6.lua
Normal file
@@ -0,0 +1,25 @@
|
||||
function Calculate_volume(height, angle)
|
||||
local r = math.tan(angle) * height
|
||||
return 1/3 * math.pi * r^2 * height
|
||||
end
|
||||
|
||||
function Tests()
|
||||
-- height, angle
|
||||
local cases = {
|
||||
{ 4.03, 3.55 },
|
||||
{ 308, 380 },
|
||||
{ 0.394, 0.826 }
|
||||
}
|
||||
|
||||
for i = 1, #cases do
|
||||
local case = cases[i]
|
||||
local height = case[1]
|
||||
local angle = case[2]
|
||||
|
||||
local volume = Calculate_volume(height, angle)
|
||||
|
||||
print(string.format("height: %f, angle: %f, volume: %f", height, angle, volume))
|
||||
end
|
||||
end
|
||||
|
||||
Tests()
|
||||
14
exercises/ch03/ex3_7.lua
Normal file
14
exercises/ch03/ex3_7.lua
Normal file
@@ -0,0 +1,14 @@
|
||||
local function random_normal()
|
||||
local u = math.random()
|
||||
local v = math.random()
|
||||
return math.sqrt(-2 * math.log(u, math.exp(1))) * math.cos(2 * math.pi * v)
|
||||
end
|
||||
|
||||
local function generate()
|
||||
for _ = 0, 10 do
|
||||
local value = random_normal()
|
||||
print(value)
|
||||
end
|
||||
end
|
||||
|
||||
generate()
|
||||
Reference in New Issue
Block a user