You can solve the brachistochrone problem using Fermat's principle, as shown in the 3blue1brown video GP is referring to. Since you're looking for the shortest time, if you can construct a lens where the speed of light is proportional to the speed of the bead on a wire, then the shortest-time wire is the path that light would take by Fermat's principle, and then you can use (an infinitesimal version of) Snell's law to find the direction of the wire at each height.