problem 21 solution in both ruby and c