exercise5.rb with edits