This sounds like a graph problem similar to the google unit conversion problem (https://alexgolec.dev/ratio-finder/). You could probably do a data driven solution, but the gist is convert to and from one normalized form. Then it's n*2 functions.
This is probably what you're implicitly doing with the class solution you're talking about.
This is probably what you're implicitly doing with the class solution you're talking about.