Wednesday, December 3, 2014

Here comes [Problem Solving] ---- Last Post

Here comes the LAST POST of my SLOG. I have learnt a lot this term and I hope we can all ACE THE FINAL EXAM and this will never happen...

Here is my problem solving of Penny piles. The problem says: 

You are sitting in front of two drawers.  The left drawer contains 64 pennies, the right drawer contains nothing.  Can you arrange things so that one of the drawers has 48 pennies, using combinations of the following two operations, l and r?


l: If the left drawer has an even number of pennies, you may transfer half of them to the right drawer.  If the left drawer has an odd number of pennies, operation l is disallowed.
r: If the right drawer has an even number of pennies, you may transfer half of them to the left drawer.  If the right drawer has an odd number of pennies, operation r is disallowed.
Choose another number in the range [0,64].  Starting from the same initial position, can you arrange things so that one of the drawers has that number of pennies? Are there any numbers in that range that are impossible to achieve? What about starting with a different number of pennies in the left drawer? 






1. UNDERSTANDING THE PROBLEM
Since this problem is long I would like to simplify the problem and gather the key information:
Beginning : (64, 0)
Try to get: (48, 16) or (16, 48) or any number in [0, 64]
By using combination of these two operations:
l: iff L = even  => (L/2, R+L/2)
r: iff R = even => (L+R/2, R/2)

2. DEVISING A PLAN
Since it only involves simple math, I can just write it down such as (64, 0) --> (32, 32) --> (16, 48) or (64, 0) --> (32, 32) --> (48, 16)
It is very easy to approach to (48, 16) or (16, 48)
How about any other numbers [0, 64] it is clearer to draw a tree diagram.

3. CARRYING OUT THE PLAN

The combinations which are not showing in the pictures are (21, 43) (53, 11) (13, 51) (45, 19) (29, 35) (61, 3). It can easily show that we can reach to any number in [0, 64] 

Since 64 pennies are not that many so we can write out all the combinations. What if there is a larger number we need to find another way to do it. The easiest way to check if we choose any number in [0, 64] see if the operation can reach to is going backwards.

Going backwards is doing this operation (L*2, R-L ) or (L-R, R*2)
For example, lets see if we can reach (14, 50)
(14, 50) --> ( 28, 36) --> (56, 8) --> (48, 16) --> (32, 32) --> (64, 0)

4. LOOKING BACK
In conclusion, we can reach whichever number we want in [0, 64] starting from the initial combination (64, 0). There are many other ways to solve this question. I have read http://cscblogger165.blogspot.ca/2014/10/week-7-polyas-approach-to-penny-piles.html
http://mycsc165courselog.blogspot.ca/2014/11/week-10-and-problem-solving-episode.html
These two problem solving episodes are very clear and thoughtful. I like using python programming to solve this question which is very smart and practical.