Updated exercise4.rb with solution