Thursday 4 April 2013

Pile of Pennies Problem

The following problem I will discuss is described as the following:

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 the following two operations:
If the left pile has an even number of pennies, transfer half of them to the right pile. If the left pile has an odd number of pennies, operation L is disallowed.

If the right pile has an even number of pennies, transfer half of them to the left pile. If the right pile has an odd number of pennies, operation R is disallowed.
What about arranging things so that one of the piles has other numbers in the range [0,64]? What about starting with a different number of pennies in the left drawer?

Understanding the Problem
- in this problem, we are trying to see if we can rearrange the drawers so that we can obtain 48 pennies in one drawer, and ultimately try to obtain any number of pennies in the range of [0,64].
- we are able to manipulate our condition by shifting pennies from drawers only if an even amount is present. This will allow us to try to obtain any number in this range. For example: If there are 20 pennies in the right drawer, we are able to transfer half of these pennies to the left draw so that 10 is remaining in the right. But, if 21 pennies are present in the right drawer, we cannot move any amount of pennies at all.

Devising a Plan
- since our desired amount of coins is any number in the range [0, 64] and 48 specifically, we can define the amount of pennies in both drawers as (x,y) where x is the number of pennies in the left drawer and y is the number of pennies in the right drawer, whose sum is equal to 64.
- we will continually add and remove pennies from each drawer using the restrictions of L and R defined in the problem to show that both x and y can be any number from [0, 64]

Carrying out the Plan
- After carrying out the operations, the following is the results of all the possible combination that can be obtained in each successive step.

Step 1: L:64, R:0 

Step 2: L:32, R:32 


Step 3: L:16, R:48 / L:48, R: 16


Step 4: L: 8, R: 56 / L: 40, R:24 / L:24, R:40 / L:56, R:8


Step 5: L: 4, R: 60 / L 36, R 28 / L20, R44 / L52, R12 / L12, R52 / L44, R20 / L28, R36 / L60, R4


Step 6: L: 2, R: 62 / L34, R30 / L18, R46/ L50, R14 / L10, R54 / L42, R22 / L26, R38 / L58, R6 / L6, R58 / L38, R26 / L22, R42 / L54, R10 / L14, R50 / L46, R18 / L30, R34 / L62, R2  


Step 7: L: 1, R: 63 /  L33, R31 / L17, R47 / L49, R15 / L9, R55 / L 41, R23 / L25, R39 / L57, R7 / L5, R59 / L37, R27 / L21, R43 / L53, R11 / L13, R51 / L45, R19 / L29, R35 / L61, R3 / L3, R61 / L35, R29 / L19, R45 / L51, R13 / L11, R53 / L43, R21 / L27, R37 / L59, R5 / L7, R57 / L39, R25 / L23, R41 / L55, R9 / L15, R49 / L47, R17 / L31, R33 / L63, R1

- As shown through this data, we have been able to obtain 48 pennies in a drawer by the third step. Furthermore, we have been able to show that all the numbers in the range [0, 64] can be obtained in as little as seven steps of initally starting. However, it is impossible to transfer 64 pennies from one drawer to the other because this would break our conditions. We wouldn't be able to transfer the last penny present in (L63, R1) or (L1, R63). Therefore as a possible restriction we can say that if a drawer has either 64 or 0 pennies, then the second drawer is unable to obtain that amount of pennies.
- if we were to start with a different amount of pennies, we would still be able to obtain any number in this range as long as the initial amount of pennies is an even number that corresponds to 2^x, where x is any number. For example if the initial amount of pennies in one drawer is 128 or 2^7, we would be able to obtain any number in the range of [0, 128]. But, if the initial amount of pennies in one drawer is 110 for example, when divided in half, this would give two odd numbers 55 and 55. This would not allow us to obtain our any number in the range because they are both odd.

Looking Back
- I feel the results shown are accurate and correctly solves the problem. Solving the problem another way may not be possible, but nothing is impossible.

Sunday 24 March 2013

Wiki Part 3

This week I got the chance to actively contribute to Wikipedia by editing a page. It was really interesting how I was able to be apart of the process of posting my own thoughts on how the page should be written. It was a really great experience for me and I aim to continue to help the Wikipedia community.

Thursday 14 March 2013

Test 2

I wrote my term test 2 in the morning. I found it easier than the last one (maybe because I had prepared for this one much longer). I felt the questions addressed where fair. But, I did get stumped on some of the written short answer questions. To be honest, I wrote down a "cheat sheet," but I felt like I didn't really need it for the test, because I was so prepared. Anyway, test was great overall and I'm glad I get to sleep in tomorrow because there is no tutorial.

Friday 8 March 2013

Ecosystem.rkt

Hello, I'm dedicating this page to writing about issues that I encountered while doing Project 1 with my partner (shoutouts to http://basedsagat.wordpress.com/). The assignment was overall quite straightforward, but some issues did arise, mainly due to problems with Racket syntax.

For example, the most trouble I had while working on the project was in ecosystem.rkt. I've gotten the code to run and produce an image of the fox gradually increasing in size while the rat is slowly decreasing. But, I don't know how to reverse the process. When the fox population reaches to high, it should drop because of competition and whatever (this isn't an ecology course) because of less rats, leading to a sudden increase in rats. I am trying to figure this out. Hopefully, I will have it done by tonight.

See you in my next post. 

Friday 1 March 2013

Wiki ... Part 2

I guess I never mentioned doing a part 1 for this assignment. Anyway, I'll mention it now. For Part 1 of this assignment, we had to find possible wiki pages that we would like to edit.

This week I primarily focused on devising an outline for my Wikipedia Assignment (Part 2). I am working on a wiki titled "Video Game Controversies." Basically, I had to detail methods on how I would be able to edit grammar and add citations in accordance to Wikipedia guidelines. I was seriously surprised to find tiny references to coding when I was reading Wikipedia's instructions on how to properly add footnotes. For example:

When you want to add a footnote to a cited source on the page, I would need to have to follow the following format Multiplayer games transcend boundaries between cultures. . <ref> Doodles, Alex. Multiplayer and Culture''. Harvard University Press, 2010, p.10 .</ref> It.... Words like <ref> and </ref> I assumed signaled the beginning and the end of the citation, but I found it very interesting to see that Wikipedia had it own method to of coding. This makes it easy for everyone to follow a certain format and always receive a desired outcome. I am starting to see that coding is a universal aspect that tries to simplify everyone's lives.

Great lesson learned, and another great week of CSC104, looking forward to next week!

Monday 18 February 2013

AGGREGATES!

This week we learned how to group values into a "list" and then used functions to manipulate that list using "map." This is a very useful idea if you wanted the same function to operate on multiple pieces of data. I found it especially difficult to understand at first, but after some experimenting on DrRacket, I sort of figured it out. I'm beginning to notice that when I play around with DrRacket, I seem to understand course concepts more better. I guess it is better to try coding on your own once you are introduced to a new concept.

Anyway, one problem I encountered when trying to figure out aggregate functions is the following. Use map and a function that you create called sub5 to transform the list (list 1 2 3 4 5) into the list (list -4 -3 -2 -1 0). In order to solve this problem, I had to first figure out how to develop a list with numbers 1 - 5 in order. I remembered from class, Professor Heap mentioned that we can use the range function to develop a list provided we tell the function how much increments the numbers will increase/decrease by. This is what I used: (range 1 6 1). This will tell DrRacket to produce a list of numbers starting from 1 and increasing by 1 until 6, but not including 6. Next, I had to define a function sub5. This wasn't hard at all since I already knew had to define functions from several weeks ago. This is what I used: (define (sub5 num) (- num 5). "num" is used as a placeholder. Lastly, we had to combine both our function and our list using the "map" function which tells DrRacket to use the function sub5 and operate it on every number in our list. This is what I used: (map sub5 (range 1 6 1)). This produced my desired answer.

This was a very interesting concept to learn and I am looking forward to class after reading week!

Thursday 7 February 2013

Fibonacci Numbers!

I just had my test a couple of hours ago and I feel great. I felt really uncomfortable going into the exam because there was a lot of material. I was afraid there would be a question on Fibonacci numbers on the test, and guess what, IT WAS ON IT. The only reason I don't like dealing with Fibonacci numbers, is because I did not understand the code that was presented. Normally, I understand expressions dealing with images and  simple calculation, but when "if" statement get into the mix, I completely lose my mind. At first glance of the question, I started to panic because I didn't know what to do. So, I tried to understand the question and realized we didn't have to do any coding. All we had to do was explain how the computer deals with Fibonacci numbers. After a long series of steps trying to explain that each Fibonacci number was dependent on previous ones, I was able to figure it out. But, it took me the majority of the test. I just checked the solutions to the problem  and I feel I had done the question correctly. Overall, I fell the test was fair. Glad that their is no tutorial tomorrow because I get to sleep in. See you in my next post.