I have some clarification regarding any equation to do some logic like
Buy 2 Get 3 Offer with repeat (means if i buy 4 then 6 to be off)
If i add 2 quantities of product to cart then another 3 number of quantities are 10% off for next 3 products
it is some thing like Product price =100 product discount = 10% so it is 10
Upto 2 product it is 200$
when i add 3rd product it cost reduce to
(3*100)-10 = 290$
for 4th one
(4*100)-20 = 380$
for 5th one
(5*100)-30 = 470$
but 6 and 7 should add original price because of repeat
ex: original price => discounted price
1,2 => 3,4,5
6,7 => 8,9,10
11,12 => 13,14,15
.. so on
Example
$buy=2,$get=3
$current_quantity = 13;
$total_quantity = $buy+$get;
for 13
i want the following series as count
example 3,4,5,8,9,10,13 total 7 so discount 1300-70 = 1230$
if buy 1 get 3 with 10% off means 13
2,3,4,6,7,8,10,11,12 total 9 so discount 1300-90 = 1210$
not sure how to get this desired result in a minimal efficient manner any help or equation will be great.
Thanks.
Suppose that $n \geq 0$ is the number of products and $p$ is the price of the product.
If $n \equiv 0 \,(mod \,5)$ ($n = 0,5,10,15,\ldots)$, then $\frac{2}{5}n$ have the original price and $\frac{3}{5}n$ have 10% discount, so the total is $$T = \big[\frac{2}{5}n\big]\cdot p + \big[\frac{3}{5}n\big]\cdot (p \cdot 0.9)$$
If $n \equiv 1 \,(mod \,5)$ ($n = 1,6,11,16,\ldots)$, then $n-1 \equiv 0 \, (mod \, 5),$ so $$T = \big[\frac{2}{5}(n-1) + 1\big] \cdot p + \big[\frac{3}{5}(n-1) \big] \cdot (p \cdot 0.9)$$
If $n \equiv 2 \, (mod \, 5)$ ($n = 2,7,12,17,\ldots)$, then $n-2 \equiv 0 \, (mod \, 5)$, so $$T = \big[\frac{2}{5}(n-2) + 2\big] \cdot p + \big[\frac{3}{5}(n-2) \big] \cdot (p \cdot 0.9)$$
If $n \equiv 3 \, (mod \, 5)$ ($n = 3, 8, 13, 18, \ldots)$, then
$$T = \big[\frac{2}{5}(n-3) + 2\big] \cdot p + \big[\frac{3}{5}(n-3) + 1 \big] \cdot (p \cdot 0.9)$$
The last case, $ n \equiv 4 \, (mod \, 5)$ ($n = 4, 9, 14, 19, \ldots$) is
$$T = \big[\frac{2}{5}(n-4) + 2\big] \cdot p + \big[\frac{3}{5}(n-4)+ 2 \big] \cdot (p \cdot 0.9).$$
I don't know if this is efficient, but in simple terms: given the total number of products that were bought, divide it by $5$, and look at the residue, which can only be $0,1,2,3,4$. Depending on the residue, apply the corresponding formula to get the total price.
The general case: Buy $x$, and get the next $y$ with discount $d$, $0 < d < 1 \, (d=.1 \implies 10$%, $d=.25 \implies 25$%, etc...).
If $n$ is the number of products, $p$ is the price of the product, and $0 \leq r < x+y \,$ the remainder of dividing $\frac{n}{x+y}$, then the total is
$$T = \big[ \frac{x \cdot (n-r)}{x+y} + r \big] \cdot p \, + \big[ \frac{y \cdot (n-r)}{x+y} \big] \cdot (1-d)\cdot p, \text{ if } r \leq x $$ or
$$T = \big[ \frac{x \cdot (n-r)}{x+y} + x \big] \cdot p \, + \big[ \frac{y \cdot (n-r)}{x+y} + (r-x)\big] \cdot (1-d)\cdot p, \text{ if } r > x.$$