Calculate a product or ratio of SI units.
For example, kg m / s s
(kilogram-meter per second squared) should return N
(newton).
The input will always be either:
- A list of symbols for SI units, space-separated (representing a product) or
- The above,
/
, and the above (representing a ratio).
The input will never contain any other characters (such as numeric literals or other punctuation).
You may assume that this will always equal a single SI unit.
Use the following symbols:
Base quantities:
s # second
m # meter
kg # kilogram
A # ampere
Derived quantities:
N = kg m / s s # newton
J = N m # joule
W = J / s # watt
Hz = W / J # hertz
Pa = N / m m # pascal
C = s A # coulomb
V = J / C # volt
F = C / V # farad
Ω = V / A # ohm (you may use the O symbol instead, for a penalty of +3 bytes)
S = A / V # siemens
Wb = J / A # weber
T = Wb / m m # tesla
H = Wb / A # henry
Examples:
m => m
N m => J
J / W => s
A J / W => C
T m m => Wb
N / A m => T
V s / A => H
J S / F A => V
s / s s => Hz
Hz kg m Hz => N
Hz s / Ω => S
Wb / H => A
V Pa S s / C => Pa
N s / m Hz => kg
V A => W
s / Ω => F
J / A s A => Ω
Shortest code (in bytes) wins.
kg m / s s
would actually be kilogam-meter-seconds per second, or just kilogram-meters. Multiplication and division work LTR. What you are looking for iskg m / (s s)
. This also applies to the other examples. \$\endgroup\$1 / 2x
really meanx / 2
? \$\endgroup\$