Logic problems solved with Ruby