-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
74 lines (58 loc) · 2.04 KB
/
main.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
local UnitWrapper = require "units"
local Conversion = require "conversion"
local units = UnitWrapper.makeUnitsTable {
"centimeters",
"feet",
"hours",
"inches",
"kilometers",
"meters",
"miles",
"minutes",
"seconds",
}
print (88 * units.miles / units.hours)
-- Output:
-- 88 miles / hours
local cmPerM = 100 * units.centimeters / units.meters
local secondsPerHour = 3600 * units.seconds / units.hours
local cmPerInch = 2.54 * units.centimeters / units.inches
local inchesPerFoot = 12 * units.inches / units.feet
local feetPerMile = 5280 * units.feet / units.miles
-- Calculate the speed of sound in air, in MPH
print ("Speed of sound", 343 * units.meters / units.seconds
* cmPerM
* secondsPerHour
/ cmPerInch
/ inchesPerFoot
/ feetPerMile)
-- Output:
-- Speed of sound 767.26914817466 miles / (hours)
print ("Inches per cm", cmPerInch ^ -1)
-- Output:
-- Inches per cm 0.39370078740157 inches / (centimeters)
print ("Hypotenuse of right triangle with sides 3 cm and 4 cm",
((3 * units.centimeters) ^ 2 +
(4 * units.centimeters) ^ 2) ^ 0.5)
-- Output:
-- Hypotenuse of right triangle with sides 3 cm and 4 cm 5.0 centimeters
print ("Area of 8.5 by 11 inch letter paper",
8.5 * units.inches * 11 * units.inches)
-- Output:
-- Area of 8.5 by 11 inch letter paper 93.5 inches * inches
print ("Speed of a paint roller",
8 * units.seconds / units.feet / units.feet)
-- Output:
-- Speed of a paint roller 8 seconds / (feet * feet)
local converter = Conversion.new ()
converter:addConversion (1000, units.meters, units.kilometers)
converter:addConversion (100, units.centimeters, units.meters)
converter:addConversion (2.54, units.centimeters, units.inches)
converter:addConversion (12, units.inches, units.feet)
converter:addConversion (5280, units.feet, units.miles)
print ("Kilometers per mile", converter:solveWithoutSubdividing (
units.miles, units.kilometers))
print ("Inches per mile", converter:solveWithoutSubdividing (
units.miles, units.inches))
print ("Inches per kilometer", converter:solveWithoutSubdividing (
units.kilometers, units.inches))