Optimal decision making in robotic assembly and other trial-and-error tasks