Monday, 24 November 2014

Assignment is SO HARD

This assignment is taking me forever to do but I feel like it's the most straight forward thus far. It took me an entire day to do but I think I enjoyed the assignment. Hopefully, its good preparation for the final exam.

Monday, 10 November 2014

Test 2 Thoughts

I thought the test went well. It was similar to the assignment. I definitely  thought it was easier than the first test. The assignment was excellent preparation for the test and I'm hoping the third assignment will become good preparation for the final exam.  I had the most trouble with the second question. You had to define the d = _____ ( something) and when I left the exam I remembered what I should have put!


def order(L):
        """ (list of numbers) -> None
Order L from smallest to largest. L is changed in-place. """ i=1
while i < len(L): j=i
while j > 0 and L[j] < L[j-1]:
L[j], L[j-1] = L[j-1], L[j] # swap L[j] and L[j-1] j=j-1

i=i+1


This question was done in tutorial. This took me a while to understand and figure out. I finally truly understood how to do it after the TA Christine did it on the board. The easiest way of thinking about figuring out how many steps there are is to think tally each step on the side of the code.

Sunday, 2 November 2014

Penny Problem

 Understand the problem


Left drawer has 64 pennies and the right one has none.


1. First Question


Can you arrange things so that one of the drawers has 48 pennies, using the following two operations:


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. 

2. Second Question


What about arranging things so that one of the piles has other numbers in the range [0,64]

3.Third Question


What about starting with a different number of pennies in the left drawer?


Devise a plan


Work Backwards

Carry out the plan

First Question
48 - 16
32  - 32
64  - 0


Second Question/Third Question: You can still be successful.
34 - 30
60 - 4
62 - 2
63 - 1
64 - 0

Look back 


Pretty simple after using the hint of working backwords.