Improve performance of Go's problem 23.