Solve problem 2 in go and ruby.