A fun problem!
My initial idea was to utilize Snell’s law, which was indeed the right idea, but I didn’t have the right constraints.
After a while I rethought the problem to minimize a multi-variable function using the “downhill simplex” algorithm.