ATM with strange policy

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.


The answer is 986.

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.

8 solutions

Ossama Ismail
Mar 10, 2017

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 1000 14 m o d 17. 1000 \equiv 14\mod 17. Modular Arithmetic mod

Then the maximum amount of money that you can withdraw is = 1000 14 = 986 = 1000 - 14 = 986 . This can be achieved as follow:-

( Withdraw/Deposit actions = current blance in the account ) 1000 306 306 306 ) = 82 82 + 221 + 221 306 = 218 218 + 221 306 = 133 133 + 221 306 = 48 48 + 221 + 221 = 490 490 306 = 184 184 + 221 = 405 405 306 = 99 99 + 221 = 320 320 306 = 14 \begin{aligned} (\text{Withdraw/Deposit actions} &= \text{current blance in the account })\\ 1000 - 306 - 306 - 306) &= 82 \\ 82 + 221 + 221 -306 &= 218 \\ 218 +221 -306 &= 133 \\ 133 + 221 - 306 &= 48 \\ 48 + 221 +221 &= 490 \\ 490 -306 &= 184 \\ 184 + 221 &= 405 \\ 405 - 306 &= 99 \\ 99 + 221 &= 320 \\ 320 -306 &= 14 \end{aligned}

Maximum amount of money that you will get after 9 withdrawals and 8 deposits = 1000 14 = $ 986 = 1000 -14 = \$986

Moderator note:

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.

Can you explain what you're doing in the equations?

E.g. it would make more sense for me to see 82, 218, etc on the RHS of the "previous" row, along with an explanation of "let's try this sequence of withdrawals and deposits".

Calvin Lin Staff - 4 years, 2 months ago

Log in to reply

I modified the equations . Thanks

Ossama Ismail - 4 years, 2 months ago
Murali P
Mar 19, 2017

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.

Siva Budaraju - 4 years, 2 months ago

Log in to reply

I agree with you. It remains to show that this can indeed be achieved.

Agnishom Chattopadhyay - 4 years, 2 months ago

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.

Laszlo Kocsis - 4 years, 2 months ago
Marta Reece
Mar 19, 2017

306 = 18 × 17 306=18\times17 , 221 = 13 × 17 221=13\times17 . So only multiples of 17 17 can be handled.

1000 = 58 + 14 17 1000=58+\frac{14}{17} , so the absolute best would be to leave only $ 14. \$14.

To accomplish this, we need to find a a and b b such that 18 a 13 b = 58 18a-13b=58 .

I did this by trial and error, with a little help of Excel. I made a table with multiples of 18 18 over the top in line 1 1 , multiples of 13 13 down column A A and then into B 2 B2 placed the formula = B $ 1 $ A 2 58 =B\$1-\$A2-58 . Copying that into the table made that zero jump right at me. So I found that a = 9 a=9 and b = 8 b=8 .

So if we take 9 × 306 9\times 306 and deposit 8 × 221 8\times 221 , 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.

Christopher Boo - 4 years, 2 months ago

Log in to reply

Thanks. Fixed it.

Marta Reece - 4 years, 2 months ago

well according to me it was 954 and i would be ok with that. :P

Abhimitra Karreddula - 4 years, 2 months ago
Sanam Amin
Mar 23, 2017

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

Alan Fruge - 4 years, 2 months ago

So basically you are trying to maximise the function 85 x + 306 y 85x+306y such that it doesn't exceed 1000. This is valid. However, you further assumed that y = 1 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.

Christopher Boo - 4 years, 2 months ago

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.

Sanam Amin - 4 years, 2 months ago
Thales Conta
Mar 22, 2017

I did a little cheating in there. I defined it as an optimization problem, setting the cost function as

max 306 m 221 n \max{306m-221n}

and with the restrictions

306 m 221 n < = 1000 306m-221n <= 1000

m n > 0 m-n > 0

and m m and n n must be integers.

The optimization returns m = 9 m=9 and n = 8 n=8 , which gives us a maximum amount of money of 986 986

Yes, this is a valid way to see the problem as an integer program. How did you solve this?

Agnishom Chattopadhyay - 4 years, 2 months ago

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.

Thales Conta - 4 years, 2 months ago
Viki Zeta
Mar 10, 2017

Just follow this simple Python code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
    bank = 1000
    me = 0
    x = []
    while bank > 0 and me < 1000:
        me += 306
        bank -= 306
        x += [me]
        if not (bank > 0 and me < 1000):
            break
        me -= 221
        bank += 221
        x += [me]
    print sorted(x)[:-1] 

If you withdraw 13 times $306 and you deposit 18 times $221, then you can get $1000. !?

Xavier Assfeld - 4 years, 2 months ago

Log in to reply

You must withdraw first to deposit. So at last if you try withdraW 306 your answer will be negativE

Viki Zeta - 4 years, 2 months ago

Can you explain what the program is supposed to be doing?

Agnishom Chattopadhyay - 4 years, 2 months ago

Log in to reply

1
print sorted(x)[:-1]

That prints the maximum amount one can withdraw.

1
sorted(x)[-1] # The last amount in the list

^ That last amount goes into negative as he cannot withdrew a solid 306

Viki Zeta - 4 years, 2 months ago
Navneeth Nivu
Mar 25, 2017
 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
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int inAtm = 1000,i;
    int withDraw = 306;
    int deposit = 221;
    int minBlc = 305;

    for(i=0;i<100;i++){
        if(inAtm >= withDraw){
            inAtm = inAtm - withDraw;
        } else if(inAtm < withDraw) {
            if(inAtm < minBlc){
                minBlc = inAtm;
            }
            inAtm = inAtm + deposit;
        }
    }
    printf("Balance %d\n",minBlc);
    printf("Max Amount Withdrawn %d\n",1000-minBlc);

    return 0;
} 

You can do much better. Your code is making 100 operations. Also, you may solve the prbblem by one equation ... 1000 % 17 1000 \% 17 .

Ossama Ismail - 4 years, 2 months ago

Log in to reply

Sure Next time:)

Navneeth Nivu - 4 years, 2 months ago

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

Ossama Ismail - 4 years, 2 months ago

Log in to reply

He he :) Ur right!

Navneeth Nivu - 4 years, 2 months ago

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?

Christopher Boo - 4 years, 2 months ago

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 :)

Navneeth Nivu - 4 years, 2 months ago
Shamant Basidoni
Mar 26, 2017

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.

Pi Han Goh - 4 years, 2 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...