Skip to content

Instantly share code, notes, and snippets.

@Cvar1984
Last active January 24, 2021 20:15
Show Gist options
  • Save Cvar1984/ec085032c2c6c376a60f08fe6fd49535 to your computer and use it in GitHub Desktop.
Save Cvar1984/ec085032c2c6c376a60f08fe6fd49535 to your computer and use it in GitHub Desktop.
--[[--
Copyright (c) 2020 Ramdhan Firmansyah
File : electric.lua
Author : Cvar1984 <[email protected]>
Date : 16.12.2020
Last Modified Date: 16.12.2020
Last Modified By : Cvar1984 <[email protected]>
--]]--
local Electric = {};
function Electric.getCurrent(v, r, p)
if p ~= nil then
return p / v;
end
return v / r;
end
function Electric.getPower(i, v)
return i * v;
end
function Electric.getVoltage(i, r)
return i * r;
end
function Electric.getResistance(v, i)
return v / i;
end
if arg[1] == nil then
print(string.format('example: ./%s %d %d', arg[0], 5, 2));
os.exit('1');
end
local volt = arg[1];
local ohm = arg[2];
local amp = Electric.getCurrent(volt, ohm);
local watt = Electric.getPower(amp, volt);
print(string.format([[
volt: %s
ohm: %s
ampere: %s
watt: %s
]], volt, ohm, amp, watt));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment