travel_problem: coding for core algorithm