G
G
Georgy Kotov2019-07-01 16:13:30
Mathematics
Georgy Kotov, 2019-07-01 16:13:30

How to find the original number?

X + 30% of Y = Y
or
X = Y - 30% of Y
Find Y where X = integer.

function search_statr_value($price, $sale, $max_price = false) {
  if( $max_price === false ) {
    $max_price = $price * 100;
  }
  $resultPrice = round(($max_price/100)*$sale);
  // Нашли !
  if($price == $resultPrice) {
    return $max_price;
  }
  if($resultPrice > $price) {
    return search_statr_value($price, $sale, $max_price/2, $max_price);
  }
  if($resultPrice < $price) {
    return search_statr_value($price, $sale, round($max_price+($max_price/2)));
  }
}
echo search_statr_value(1499, 30);

It turned out such an inefficient code on a binary search (like that). How to improve performance or use a different approach to achieve the goal?
And yes, yes, yes) I put the price and discount, wanting to get the "old price".

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Sokolov, 2019-07-01
@agsDevelopment

only neural networks need to be solved!
X = 0.7 * YWhat is difficult here? Find all pairs (X, Y) where both are integers ?
Whether the skis do not go ..

function search_start_value($price, $sale) {
  return $price * 100 / (100 - $sale);
}
echo search_statr_value(1499, 30); // 2141,4285714286

Y
YURIY KOZLOV, 2019-07-01
@WizardNG

Math, Grade 3
X+0.3*Y = Y
X = Y - 0.3*Y
X = 0.7 * Y
Y = X / 0.7

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question