Ohm's law tells us that the current (I) in amps flowing through a resistance (R) in Ohms when a voltage (V) is applied across it is given as follows:
V = I / R
Similarly the power (P) in watts dissipated by that resistance is given by:
P = V * I
By rearrangement and substitution, formulae may be derived for calculating two of these quantities when any of the other two is given. These formulae are summarised as follows (note this image uses E
instead of V
for volts):
Given an input of any two of these quantities in a string, output the other two.
- Input numbers will be decimals in whatever format is appropriate for your language. Precision should be to at least 3 decimal places. (IEEE 754-2008 binary32 floats are sufficient.)
- Each input number will be suffixed with a unit. This will be one of
V A W R
for Voltage, Amperage, Power and Resistance (or the equivalent lowercase). Additionally, you may useΩ
instead ofR
. The units will not have any decimal prefixes (Kilo-, milli-, etc). - The two input quantities will be given in any order in one string, separated by a single space.
- Input quantities will always be real numbers greater than 0.
- Output will be in the same format as input.
- Equation-solving builtins are disallowed.
Example Inputs
1W 1A
12V 120R
10A 10V
8R 1800W
230V 13A
1.1W 2.333V
Corresponding Outputs
1V 1R
0.1A 1.2W
1R 100W
120V 15A
2990W 17.692R
0.471A 4.948R
It should be noted that solutions to this challenge will effectively be self-inverses. In other words if you apply a solution to input A B
and get output C D
, then apply a solution to input C D
, then the output should be A B
again, though possibly out of order and perturbed due to FP rounding. So test inputs and outputs may be used interchangeably.