Sunday 2 December 2012

Final Tutorial Worksheet

I began working on tutorial #9. As I was working on the definition for spiral, I encountered a problem... Dr. Racket asked me to increase the memory that it uses. I followed Dr. Racket's requests and increased the memory. Then I ran the program again. A few seconds later, another message popped up, again asking me to increase the memory. I continued to do this for a couple more times, knowing the something was wrong, but not knowing what to do about it. My computer started acting weird, and started shutting down all of the programs. I sat there very confused since this had never happened to me before.

Later that day, I was going to see Prof Heap to ask a couple of questions about project #2. I decided to show him the definition I was working on. He continued on to suggesting why I was having those errors...

The moral of the story is, when you are doing recursion, you have to make sure that there is a condition. My definition did not have a condition in it and therefore it continuously was programmed into the computer but had no signal to stop. By making a baseline condition, you are giving the computer a way to output the information, without a condition, the computer just keeps going in circles.. OPPSS. Lets just say I learned a big lesson today.

In the long run, I am happy that I made that mistake, because now I will never forget that a recursive function needs a condition!


(define (spiral n)
  (cond
    [(equal? n 0) (vertical-line 10)]
    (else
     (beside/align
      "bottom"
      (vertical-line (+ 10 (* 2 n)))
      (rotate 90 (spiral (- n 1)))))))
                    

Tuesday 27 November 2012

Nearing the end...



I am excited to see what the last class has in store for us. It has been a very interesting course so far. I have exponentially increased my programming knowledge (from almost 0 to a basic understanding of programming). Our recent classes on recursion have really force me to understand the programming and what happens with each command.

Tuesday 6 November 2012

Project One: Polya's Approach to a problem

Project 1:

Using Polya’s approach:
Here is the problem that I am trying to solve.
; clarify-color : color -> color
; Make alpha 0 for colors with r+g+b > 650, leave other colors as-is
;
; !!! create two (check-expect ...) expressions for clarify-color
; insert them before the definition
(define (clarify-color c)
  (make-color
   (color-red c)
   (color-green c)
   (color-blue c)
   (cond
     [(> (+ (color-red c) (color-green c) (color-blue c)) 650) 0]
     [else (color-alpha c)])))

Understanding the problem:

I have to create two check-expects for this expression of clarify-color. I understand that if the values for r g and b add up to more than 650, alpha should be changed to 0. If they are less than 650 than alpha can stay as is.

Devising a plan:

I need to create 2 check expects. The goal of my check expects is to give a couple of examples of how this function is supposed to work. I know that I am trying to input colours instead of retrieve them.

Carrying out the plan:

(check-expect (clarify-color (make-color 220 220 220 220))
            (make-color 220 220 220 0))

(check-expect (clarify-color (make-color 20 15 25 10))
            (make-color 20 15 25 10))

 Looking back:

I can prove that it is correct. Example  1 is saying that we want to produce a color that is made of up 4 numbers (r g b a). On the next line, it is making a color of r g b a, but  first it is checking to see if the 1st make-color of r g b is greater than 650. If it is, than alpha is changed to 0, if it is not greater, than alpha is kept the same. So in example #1 r g and b add up to greater than 650 therefore alpha is 0, but in example 2, r g and b do not add up to 650 which is why alpha stays the same.

I originally made a mistake...

(check-expect (clarify-color c)
  (make-color
   (color-red c)
   (color-green c)
   (color-blue c)

I found out that what I had done retrieves the colours instead of inputting them. (make-color 220 200 200 200) takes a colour and makes a colour with the given values (r g b a).


Saturday 27 October 2012

Pixels

Opppss.. I forgot to post this. I sent it to my email since I did not have my blogger password available when  I wrote this..
I am having trouble completing exercises 8.33-8.35. Each of these questions deals with two challenges; pixels and movement. I began my search on Google, trying to figure my pixel problem out. My search led me to a very complicated page, which did not further assist me with my queries. So I decided that I was going to make my way to see Professor Heap at 5pm. We worked on 8.35- “develop an animation of a rectangle initially 1 x 2, which grows by 1 pixel in height and 2 pixels in width at each clock tick, centered in a 200 x 200 window.” The hardest part was to figure out how to make the picture grow 1 x 2 pixels. Prof. Heap had an idea to use one placeholder (x) and 2 times that placeholder (2x). So here is what it looks like..
;double-rectangle: number-> image
;draw-rectangle w by 2w centered on 200 x 200

(check-expect (double-rectangle 1
            (overlay
                        (rectangle 1 2 “solid” “yellow”)
                        (rectangle 200  200 “solid” “white”)))

(define (double-rectangle w
            (overlay
                        (rectangle w (* 2w) “solid” “yellow”)
                        (rectangle 200  200 “solid” “white”)))

(big-bang 1
            (on-tick add1)
            (on-draw double rectangle))


Thank you for your help Prof Heap!

Thursday 11 October 2012

Post Test Reflection

So to respond to the question posed in my last blog as to how I am enjoying the course and have I really gotten over the shock factor.... I am pleased to say that I am feeling right at home (or as close to home I could ever be to this foreign computer language) in CSC104. This is not to be confused with finding the course easy. Far from it, I am challenged each week in class with new information, harder than the last; which comes just as I have finally grasped the last week's material... It takes an entire week, with many hours of work to understand and remember how to correctly program what we learned the previous week. Right now, for example, I am still struggling with how to change the colours of a picture (ex take out the green etc, which we did in class yesterday). What am I going to do to make this material easier? I am going to wait for the tutorial exercise to be posted. Hopefully it will be related to what we learned last class, in which case, with some extra practice I will hopefully be on track to better understanding the material. If that does not help, then I will search through the online textbook trying to find the section that further explains what I am having trouble with. If that is too unsuccessful, I will turn to my best friend google and hope for some assistance.

Opps... I think I forgot to mention the test...

First of all, I was surprised that the test was only worth 10% when I check the previous week. In hein-sight I wish it was worth a little more, but at the time, I was really happy. I was nervous about the test, not knowing what to expect and how much detail we had to know. But, after taking the test, I realise that I studied really hard and that I was ready for the test :). One thing that made studying for the test easier was that I had already done a majority of my studying the previous weeks, while studying for the quizzes and working on the tutorials.

So to conclude.. I am enjoying the class, am still a little scared that the programming will get way over my head, but also a little bit more confident in my programming abilities. I think that is a small cause for celebration :D

Saturday 6 October 2012

Three, Two, One, Blastoff!!

I know I am a little late on this post, but regardless, I am going to blast into the past, back to week one and two of class and share my thoughts with you. This is the beginning of my programming adventure... I am extremely nervous, hesitant and well, scared.

I signed up for this class in August with an understanding that I was going to learn lots about computers as well as a LITTLE BIT of programming.

I really enjoyed the programming we learned in class 1. It was extremely basic and it didn't take long until I was bragging to my dad (who is a computer programmer) that I knew how to do so many cool things. After the first week of class, green star quickly became my favourite image to draw: (star 30 "solid" "green"). Being a little naive, I thought that the rest of the semester would continue to be this straight forward and simple.

Needless to say, after class 2, I was beginning to have second thoughts. (I did not realise how heavy a focus this class would have on programming :P) I had an instant flashback to my grade 9 computers class, where I struggled with understanding our small unit of 'Turing'. WHY did I choose to use up my last first year elective with a programming class??? What was I thinking?


Stay tuned for the next post to find out if I am surviving CSC104...