problem 13 in C
problem 13 in ruby