Improve krasnoukhov.rb solution