solution.rb for median