ruby implementation is solved, using a recursive solution. (does not pass judge)