Given a list of SI base units, a list of equations and a target, you must derive the units of the target using only the base units.
The International System of Units (SI) specifies a set of seven base units from which all other SI units of measurement are derived. Each of these other units (SI derived units) is either dimensionless or can be expressed as a product of powers of one or more of the base units.
For example, the SI derived unit of area is the square metre (m2), and the SI derived unit of density is the kilogram per cubic metre (kg/m3 or kg m−3).
The seven SI base units are:
- Ampere, A
- Candela, cd
- Kelvin, K
- Kilogram, kg
- Metre, m
- Mole, mol
- Second, s
d [m] m [kg] t [s]
v = d/t a = v/t F = m*a E = F*d
G [cd] L [m] y [A] a [K]
T = y*y/L A = T*G
The units will be always be given in the form
a will be a single uppercase or lowercase alphabetical letter and
b will be a unit (one or more characters).
The equation will be in the form
a = c
c will be an expression which will only ever use previously defined units and the operators
Powers must be expanded. For example, the unit of area is officially
m^2, but you should represent this as
m*m. The same applies to negative powers such as speed (
m*s^-1) which should be represented as a division:
m/s. Similarly, the units for acceleration,
m*s^-2, should be represented as
You do not have to do any cancelling out. For example, an output
C*s/kg/s is valid even though it can be cancelled down to
There is no specific order for the multiplication:
s*kg/m are all valid (but
/m*s*kg is invalid).
Note: You will never have to divide by a derived unit.
The shortest code in bytes wins