Solution to traveling salesman problem as specified by Codeeval