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:
L 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.

R 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.

Friday, 1 February 2013

The "big-bang" theory

This week was really interesting. We've finally moved on from manipulating static images to making small animations. We've learned about a new built in function known as "big-bang." The name itself caught my attention because I frequently watch The Big Bang Theory. The "big-bang" function takes any image and is able to animate the image using functions known as event handlers. An event handlers is somewhat self-explanatory. It just means that it controls the actual event that is occurring in the animation, whether it be a rotation, reflection, how many ticks/per-second, etc.

I actually understood this weeks content and really enjoyed, but one problem I had that was really minor occurred. I had the perfect animation created with a triangle being rotated clockwise, every half second. But, I didn't like the fact when the image was rotating, some parts of the triangle were not being shown. I didn't know how to make the animation window larger. So I toke a wild guess and thought that because (on-draw show-it) is the event-handler that actually produces that image in the window, I thought that I could increase the y-axis of the window by placing a number there to actually see all of our magnificent triangle. It ended up working, and when I actually went to review the Events Video, Professor Heap actually did make his window larger for the fish using the same method. I was really happy. If your interested, I have posted a copy of both the original code and the new code if you would like to see this minor problem. Make sure to to enable picturing-programming on intermediate student with lambda though!

Original: (big-bang (triangle 100 "solid" "black") (on-tick rotate-cw 1/2) (on-draw show-it))
New:     (big-bang (triangle 100 "solid" "black") (on-tick rotate-cw 1/2) (on-draw show-it 100 105))

This week has been a great week, and I am looking forward for next week's lecture and test.





Friday, 25 January 2013

Learning to define variables

As I mentioned in my last post, I really wanted to know how to create a definition so that I can make simple phrases represent large pieces of code. Luckily, we got to learn this early on in the course. This week I learned how compose of definition, set identifiers for a specific value, and properly used check-expect statements to prove code.

First off I'd like to say that composing a definition was actually easier than I though. I have no idea what I was doing in my last week's problem, but I am confident I would be able to tackle that problem easily now. For example, I learned that simple phrases like "tippy-toes" can be defined to resemble an image of a robber on his tiptoes or anything else. This is fascinating function and I know I will readily use this throughout the course.

Second, I learned that I can set definitions to represent long pieces of code that is relatively too long to write or tedious to copy and paste over and over again. Especially in scenarios when codes needs to be recycled repeatedly, composing definitions will surely reduce my time spent on dull tasks and keep me happy. = )

Thirdly, after a long time spent glued to DrRacket, I finally understood the purpose of the check-expect statements. These are tools used to verify whether or not subsequent code resembles our check-expect statements. I'd like to recount a certain problem I had encountered with this tool. When I first watched the tutorial video, I was completely lost.  I understood the reason for writing a contract and purpose statement, which was to explain to the viewer what the upcoming code was about.  But, words like pic:hacker and pic:calender being repeated over and over again really scared me. So, I decided to write the code out on DrRacket for myself and understand it line by line. Soon after I realized that pic:calender, etc., represented placeholders for an actual image. They themselves can be thought of as definitions of a certain image. So, instead of using those words I used random images and developed my own check-expect statements. When I wrote my actual code, it passed the tests! I was glad that I got to figure it out.

It has been a great week, and I'll see you in my next post!

Friday, 18 January 2013

Impressions of CSC104

Hi, my name is Bilal Negash and I'm a first year student. This isn't the first time I am writing a blog. I've previously made one in my last year of high school English. It wasn't as successful as I hoped it would be, mainly because I had only posted ONCE. I guess it was due to a lack of dedication for the material. I intend to fully commit myself to blog once a week for the rest of the semester, letting you know my personal impressions and feelings about this course.

First off, I'd like to quickly mention that I really like Professor Heap as our lecturer. I can tell that he is very enthusiastic about the material and is really passionate about computer technology in general.  I am looking forwards to a wonderful semester in the course with him.

Secondly, I'd like to discuss DrRacket, a programming application used for the course. I've personally had some programming experience in the past with Visual Basics, but I've got to say I really like DrRacket. Mainly because the computer language interface is really user - friendly. Although the language may seem weird at times, ex. putting + or - signs at beginning of code, it makes sense, in retrospective, that it is tedious to put multiple signs when there are a lot of numbers. One problem that I encountered when fooling around with DrRacket was trying to define a variable. After watching the " expressing values tutorial videos," I wanted to see if it was possible to define a variable, "image-area," by multiplying two default definitions "image-width" and "image-height." With no luck, I was unable to figure this out. But, I realized that we weren't expected to know how to define variables yet, since the upcoming DrRacket videos involved definitions. I guess curiosity got the better of me. In order to better prepare myself for this course, I shall look through the picturing program pdf. and understand how to properly define and express variables.

This is all I have to say for my first blog. This is a wonderful and engaging class and I hope everyone is able to benefit from this course as much as I hope too.