added solution for prob39.rb