Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def isAdmissibleOverpayment(prices, notes, x)
- y = 0
- price_difference = 0.0
- original_price = 0.0
- while (y < notes.length)
- if notes[y].include?("higher") then
- string = notes[y]
- z = 0
- amount = ""
- while (string[z] != '%')
- amount = amount + string[z]
- z = z + 1
- end
- amount = amount.to_f / 100
- original_price = (prices[y] / (1 + amount.to_f))
- price_difference = price_difference + (prices[y] - original_price)
- end
- if notes[y].include?("lower") then
- string = notes[y]
- z = 0
- amount = ""
- while (string[z] != '%')
- amount = amount + string[z]
- z = z + 1
- end
- amount = amount.to_f / 100
- original_price = (prices[y] / (1 - amount.to_f))
- price_difference = price_difference - (original_price - prices[y])
- end
- y = y + 1
- end
- if price_difference < 1 and price_difference > 0 and x == 0 then
- return false
- end
- price_difference = price_difference.floor
- if price_difference <= x then
- return true
- else
- return false
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment