brewersfan1976

is_admissible_overpayment.rb

May 30th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.47 KB | None | 0 0
  1. def isAdmissibleOverpayment(prices, notes, x)
  2.     y = 0
  3.     price_difference = 0.0
  4.     original_price = 0.0
  5.    
  6.     while (y < notes.length)
  7.           if notes[y].include?("higher") then
  8.              string = notes[y]
  9.              
  10.              z = 0
  11.              amount = ""
  12.              
  13.              while (string[z] != '%')
  14.                    amount = amount + string[z]
  15.                    z = z + 1
  16.              end
  17.              
  18.              amount = amount.to_f / 100
  19.              original_price = (prices[y] / (1 + amount.to_f))
  20.              price_difference = price_difference + (prices[y] - original_price)
  21.           end
  22.              
  23.           if notes[y].include?("lower") then
  24.              string = notes[y]
  25.              
  26.              z = 0
  27.              amount = ""
  28.              
  29.              while (string[z] != '%')
  30.                    amount = amount + string[z]
  31.                    z = z + 1
  32.              end
  33.              
  34.              amount = amount.to_f / 100
  35.              original_price = (prices[y] / (1 - amount.to_f))
  36.              price_difference = price_difference - (original_price - prices[y])
  37.           end
  38.                
  39.           y = y + 1
  40.     end
  41.              
  42.     if price_difference < 1 and price_difference > 0 and x == 0 then
  43.        return false
  44.     end
  45.        
  46.     price_difference = price_difference.floor
  47.    
  48.     if price_difference <= x then
  49.        return true
  50.     else
  51.        return false
  52.     end
  53. end
Advertisement
Add Comment
Please, Sign In to add comment