Solve problem 3 for both ruby and golang.