Skip to content

Instantly share code, notes, and snippets.

@CMCDragonkai
Last active January 1, 2021 06:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CMCDragonkai/c438c3245b81dc575612897dd1d5c217 to your computer and use it in GitHub Desktop.
Save CMCDragonkai/c438c3245b81dc575612897dd1d5c217 to your computer and use it in GitHub Desktop.
Combine Discounts #python
#!/usr/bin/env python
def combine_discount(d1, d2):
return (d1 + d2 - d1 * d2)
print(combine_discount(0.4, 0.42)) # 0.652

How to Combine Discounts

Suppose you have $1000 dollars, and you are applying 40% discount first, then 42% discount second.

What is the total discount?

1000 - 0.4*1000 - (0.42 * (1000 - 0.4*1000)) = 348
I - D1*I - (D2 * (I - D2*I)) = O
I - D1*I - D2*I + D1*D2*I = O
I(1 - D1 - D2 + D1*D2) = O

We know that:

I*f = O
I - (1 - f)I = O

So plugging the above as f. Then:

I - (1 - (1 - D1 - D2 + D1*D2))I = O

The resulting percentage is:

(1 - (1 - D1 - D2 + D1*D2))
1 - 1 + D1 + D2 - D1*D2
D1 + D2 - D1*D2

Tadaa!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment