Go port from Java code of Algorithms Text book.