rewrite exercise3.rb to use case