-Demosthenes- Posted October 25, 2006 Share Posted October 25, 2006 Is there an equation for this problem? Each candy bar comes with a coupon, if you get 7 coupons it's good for a free candy bar. What is an eqation that gives you the final amount of candy bars you get (including free ones) using X as the originial number you bought? EX if I bought 27 candy bars, I'd get 27 coupons > 3 free bars + 6 left over coupons. But then those 3 will come with 3 more coupons, making the total amount of coupons 9, which is enought to get another candy bar. So, in the end I'd have 31 candy bars. And it gets even more difficult with higher numbers. This question was given in class (too late to get any credit for it ), but I could never solve it. Link to comment Share on other sites More sharing options...
JesuBungle Posted October 26, 2006 Share Posted October 26, 2006 Errr. You had me workin on this for 3 hours and all I got was an indentation from a pencap on my forehead:-( Link to comment Share on other sites More sharing options...
-Demosthenes- Posted October 27, 2006 Author Share Posted October 27, 2006 I have no idea. Link to comment Share on other sites More sharing options...
uncool Posted November 1, 2006 Share Posted November 1, 2006 I believe the answer should eventually come out to floor(x + x/b + x/b^2 + x/b^3) = floor(x*b/(b-1)) where x is the original number you had and b is the number you need to get a free bar. In your example, it's floor(27*7/6) = floor(63/2) = 31. =Uncool= Link to comment Share on other sites More sharing options...
uncool Posted November 2, 2006 Share Posted November 2, 2006 A reason for my answer below: Let us define a function f(a, b) = floor(a/b) + f(a - b*floor(a/b) + floor(a/b), b) f(a, b) = 0 if 0 <= a < b I say f(a, b) = floor(a/(b-1)). Clearly, all cases do go to the base case shown above. Now, we will use WOP to show that this is the case in general. Let us assume that a is the lowest number such that f(a, b) =/= floor(a/(b-1)). Then f(a) = floor(a/b) + floor(a/(b-1) - b*floor(a/b)/(b-1) + floor(a/b)/(b-1)) = floor(a/b) + floor(a/(b-1) - floor(a/b)/(b-1) - floor(a/b) + floor(a/b)/(b-1)) = floor(a/b) + floor(a/(b-1) - floor(a/b)) = floor(a/b) - floor(a/b) + floor(a/(b-1)) = floor(a/(b-1)). This function is equal to the number of bars you get if you start out with a coupons and redeem b coupons for a bar each time. Therefore, if you start out with ab bars, you get floor(ab/(b-1)) bars at the end. =Uncool- Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now