Tuesday, 4 February 2014

Brian's CSC148 SLOG # 3

Hello and how is everyone?

Boy, has this week has been rough!
Learned a lot in the 148 labs but the assignment is kicking my behind!

The first assignment was going swell until the 5th part, Tour.py.
I am unsure how to optimally make my program solve the problem. We are supposed to use recursion but my experience with it isn't sufficient.

I have tried a number of things through-out the entire day and I can't seem to find the root of the issue. For example, my code is supposed to solve the game with 4 stools and 5 cheeses in 13 moves but it has been giving me different values of moves like 21 or 7. I traced my program and realized there was an issue but it's a strange one due to the conditions of the formula for the minimum amount of moves.

Basically, when the formula calls on itself again, it uses a value that is not specified in the formula, so it has been returning a NoneType + an int. What happens when you add a NoneType and int? TypeError! Still working feverishly on this issue, trying to figure out where I'm going wrong.

Oh yes! There was a very interesting concept we learned this week in the labs.

  • copy.copy
  • copy.deepcopy
  • assigning values to variables

Basically, when you assign a value to something in python, it will be stored in memory address.
If you assign another variable equal to that value, and equate them with '==', this will return True.

copy.copy and copy.deepcopy will create a copy of the variable, BUT they will be assigned at different memory addresses.

EDIT: Oops! I made a mistake in my last post about these built-ins. Please disregard them and read here.
.
copy.copy and copy.deepcopy will both change the memory addresses of the variables! Equating them as they are will still be return True. However, recall what happens if these variables are both assigned to a number and you add to one of them. If copy.copy or copy.deepcopy is not used, adding to this number will change both variables and they can be equated to return True.

Now try it again with these two copy functions and add to one of the variables and what happens?
The answer: The number with the variable you have added to will be assigned the new value and the other variable will remain unchanged. Interesting stuff!

Thanks for reading my SLOG again.
Back to the assignment for me!








No comments:

Post a Comment