Solve problem 4 for both ruby and golang.