There is a faulty ATM machine which only allows you to withdraw exactly $306 or deposit exactly $221 each time. If you try different amounts, it would reject your transaction.
You have $1000 in your bank account but $0 on you. You are desperate to get as much money out as possible. Using multiple transactions, what is the maximum net amount of money (in $) that you can obtain?
Clarification:
The answer is the sum of withdrawals minus the sum of deposits.
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
This solution does an excellent job producing both necessary parts:
a.) Demonstrating that $986 is the theoretical maximum.
b.) Demonstrating via the actual steps that $986 is in fact possible.
While it's possible to "answer the question" with only a.) or b.), a full mathematical proof requires both.
HCF of 306 and 221 is 17. The closest multiple of 17 to 1000 is 986.
You have proved an upper bound, but you have not shown how 986 can be achieved.
Log in to reply
I agree with you. It remains to show that this can indeed be achieved.
Yes, it was missing from the solution. ax+by=c is a linear diophantine equation, which has solution if the greatest common divisor of a and b is a divisor of c. Look up the proof at https://en.wikipedia.org/wiki/Diophantine_equation
We don't need to show how it can be achieved, only that it can be achieved. The only thing that remains is to state that we do our withdrawals only when we have more than 305 on our account.
3 0 6 = 1 8 × 1 7 , 2 2 1 = 1 3 × 1 7 . So only multiples of 1 7 can be handled.
1 0 0 0 = 5 8 + 1 7 1 4 , so the absolute best would be to leave only $ 1 4 .
To accomplish this, we need to find a and b such that 1 8 a − 1 3 b = 5 8 .
I did this by trial and error, with a little help of Excel. I made a table with multiples of 1 8 over the top in line 1 , multiples of 1 3 down column A and then into B 2 placed the formula = B $ 1 − $ A 2 − 5 8 . Copying that into the table made that zero jump right at me. So I found that a = 9 and b = 8 .
So if we take 9 × 3 0 6 and deposit 8 × 2 2 1 , we should be fine.
We can only add money when we have it, so that requires collecting enough cash for the purpose. If everything is handled in $20 and $1 bills, there should be no problem with the currency. We can simply alternate between taking out and putting back 8 times, then take out one more withdrawal.
You are right. The other solutions don't explain how to perform the transactions such that no overdrawing or having no money for deposit happens. Thumbs up!
P/S: you might want to check your second equation.
well according to me it was 954 and i would be ok with that. :P
306 - 221 = 85. So, you have two functions you can perform: add 306 or add 85. 85, being the smaller number, and subsequently approaching 1000 with less difference, will become 85x < 694, because 85x + 306 cannot be higher than 1000. 85* 8 = 680. 680 + 306 = 986 .
I solved it this way too
So basically you are trying to maximise the function 8 5 x + 3 0 6 y such that it doesn't exceed 1000. This is valid. However, you further assumed that y = 1 , how is this true? Say if your bank account has 612, and you want to take the most out of it. Your solution will give 561 but the optimal solution is to withdraw 306 twice.
Log in to reply
True; I based the assumption that y = 1 on account of 85 and 306 approaching 1000 with more difference than the function. I assume that most who solved the problem first decided to see how closely 306 can approach 1000, and subsequently 85. The next logical step would be to use 85x + 306 <= 1000 and 306x + 85 <= 1000, and this yielded results.
I did a little cheating in there. I defined it as an optimization problem, setting the cost function as
max 3 0 6 m − 2 2 1 n
and with the restrictions
3 0 6 m − 2 2 1 n < = 1 0 0 0
m − n > 0
and m and n must be integers.
The optimization returns m = 9 and n = 8 , which gives us a maximum amount of money of 9 8 6
Yes, this is a valid way to see the problem as an integer program. How did you solve this?
Log in to reply
I solved it in Excel, using the Solver. In the Constraint box, besides the restrictions of the problem, I set m and n to integers, and used the LP Simplex algorithm. Actually, pretty simple to solve using this tool from Excel.
Just follow this simple Python code
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
If you withdraw 13 times $306 and you deposit 18 times $221, then you can get $1000. !?
Log in to reply
You must withdraw first to deposit. So at last if you try withdraW 306 your answer will be negativE
Can you explain what the program is supposed to be doing?
Log in to reply
1 |
|
That prints the maximum amount one can withdraw.
1 |
|
^ That last amount goes into negative as he cannot withdrew a solid 306
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
You can do much better. Your code is making 100 operations. Also, you may solve the prbblem by one equation ... 1 0 0 0 % 1 7 .
Don't worry about your code, I am sure that you can do much better. By the way from time to time I'm writing a codes to solve some problems like this one...hahaha
The algorithm doesn't seem right. It assumed that whenever the amount in the atm is lower than what you can withdraw, you can always deposit. If initially there were 305 instead of 1000, the program would return 289.
I believe it can be fixed, but I'm still thinking. Any idea?
Log in to reply
Actually, 305 is the max balance amount that you cannot withdraw! That is why I set it to 305! And there are many ways this algorithm can be modeled! For me, I didn't find a paper and pen to manually add up and subtract for many iterations, So I wrote a simple program for just answering this question, later I thought of putting it in original answers. As @Ossama Ismail sir mentioned it can be written in a single line :)
It can be viewed like this You can remove either 85 ( difference between two numbers ) or remove 306 ...now maximising 85x + 306y < 1000 for values of integral x and ys we get the max as 986 Where x and y are no. Of 85s and number of 306s taken out respectively... I'm new please point out if I'm wrong
Yeah, you understood the question correctly. Now's what left is how to get the numerical answer.
Problem Loading...
Note Loading...
Set Loading...
Both 306 and 221 are multiple of 17, you can withdraw only multiple of 17. The largest multiple of 17 not exceeding $1000 is $986. Or You will withdraw $986 leaving $14 in your account 1 0 0 0 ≡ 1 4 m o d 1 7 . Modular Arithmetic mod
Then the maximum amount of money that you can withdraw is = 1 0 0 0 − 1 4 = 9 8 6 . This can be achieved as follow:-
( Withdraw/Deposit actions 1 0 0 0 − 3 0 6 − 3 0 6 − 3 0 6 ) 8 2 + 2 2 1 + 2 2 1 − 3 0 6 2 1 8 + 2 2 1 − 3 0 6 1 3 3 + 2 2 1 − 3 0 6 4 8 + 2 2 1 + 2 2 1 4 9 0 − 3 0 6 1 8 4 + 2 2 1 4 0 5 − 3 0 6 9 9 + 2 2 1 3 2 0 − 3 0 6 = current blance in the account ) = 8 2 = 2 1 8 = 1 3 3 = 4 8 = 4 9 0 = 1 8 4 = 4 0 5 = 9 9 = 3 2 0 = 1 4
Maximum amount of money that you will get after 9 withdrawals and 8 deposits = 1 0 0 0 − 1 4 = $ 9 8 6