Wednesday, March 26, 2014

CSC-9 Structured Data

   This week we talked about the structured data. We learned two new functions which are flatten and filter respectively.
   First of all, we know how to make string into image
(define (string->image a-string)
(text a-string 12 "orange"))
   Secondly, I know that the flatten function spend all the list together. These materials in the lectures are easy to understand so that I do not want to talk much about those functions. What I want to record in my blog is how I figure the using of "filter" function.

   We mentioned the filter function in the lecture but professor did not talk much about it. We need to do some practices at home to prepare for the weekly quiz.
Here is an example:
(require picturing-programs)
(define (abc im)(< (image-height im) (image-width im)))
(define L2 (list (rectangle 50 100 "solid" "blue")
                  (beside (rotate-ccw (triangle 50 "solid" "green"))
                             (rotate-cw (triangle 50 "solid" "green")))
                             (circle 50 "outline" "red")
                             (rectangle 100 50 "solid" "black")))

(check-expect (list (beside (rotate-ccw (triangle 50 "solid" "green"))
                            (rotate-cw (triangle 50 "solid" "green")))
                            (rectangle 100 50 "solid" "black"))
                            (filter abc L2))
The process I figured it out is that:
1) I need to write a predicate that determines whether an image is wider than its tall.
so I define abc functions: (define (abc im)(< (image-height im) (image-width im)))
2) I need to find out the suitable element from the L2. Here I need to use "filter". I found that its function is very similar to "map". "map" need two arguments and so "filter" does.
After practicing three examples, I finally get familiar with this structure: listing out the condition first, so that it is able to find the suitable elements from the list.

Thursday, March 20, 2014

CSC-8 Binary notation

        This week we are going to take the second term test. We talked more about the binary notation. For instance, we discussed about the addition and multiplication of the binary notation. It is hard to understand at first in the lecture. However, when I did the past test I realized that it is quite easy and similar to the addition we did with the regular number. It will also carry to the next digit, such as 2: 1 0 etc., For example:
   1 1 0 1
+    1 0 1
1 0 0 1 0
For the first step, 1+1=2 (1 0) carries 1 to the left. Then (0+0+1=1). The following third and forth step are the same as the first step we took. Finally, we will get the final answer 10010.
The multiplication is the same as addition:
         1 1 0 1
X         1 0 1
         1 1 0 1
      0 0 0 0
   1 1 0 1
1 0 0 0 0 0 1
Tomorrow will be our second term test, I will focus on reviewing the recursion and binary notation.

Tuesday, March 11, 2014

CSC 7-- Recursion

    This week, we talked more about the recursion. After taking the lecture in the morning, I did some practices in Dr. racket to be familiar with the recursion function. One of the practices is so classical in the Computer Science that it has four arguments in the function. I think it is complicated but I deal with the difficulties by writing out all the step one by one in the Dr. Racket. After listing all the steps, I can explain each step easier than doing it directly with the complicated function. Here is an easy example I did as my practice.

(require 2htdp/image)
(define serp0
  (circle 15 "solid" "green"))

(define (serp d)
  (if
   (zero? d)
   serp0
   (above
    (serp (sub1 d))
          (beside
           (serp (sub1 d))
           (serp (sub1 d))))))
it will produce as followed: 
Personally, the best way to understand the complicated function is to do it again by your own and change some arguments in the function. Here is a classical and complicated example.
(define (k d)
  (cond
    [(> d 0)
     (beside/align
      "bottom"
      (k (- d 1))
      (rotate 60 (k (- d 1)))
      (rotate -60 (k (- d 1)))
      (k (- d 1)))]
    [else (line 5 0 "blue")]))
This week, we will begin to do some programming project. I hope I can share some thoughts with you guys in this blog when I begin to touch the assignment. 

Wednesday, March 5, 2014

CSC 6 Apply Function and Tracing Recursion

This week we talked about the apply function and tracing recursion.
At first, I was confused about  the differences between apply function and Map function. After doing practices in Dr. Racket, I realized that Apply function is useful when there are multiple arguments in numbers of functions. 

Also Tracing Recursion is very difficult for me to understand at first since the steps repeat again and again in the function. In order to understand the procedure of the function, I plugged in each number carefully and do some practices on papers to help me follow how the function run. Then when professor play the Tracing Recursion function with images and shapes, it becomes an interesting topic in the course. But the most important thing to do with the Tracing Recursion is to keep yourself calm and keep your brain awake!

Last but not least, this week we need to finish implementing the contributions to Wikipedia. I did submit it. I spent almost half day to finish this assignment. I need to make three contributions as I planned in my part A, which are uploading a picture, updating the information and adding a lead section. For the first one, I need to upload it to Wikicommons first so I can use the link in my sandbox. For the second article, I updated the new ratings information for a TV series which need reliable reference. I think that the step to make a link for reference is quite tough for me. I found a lot of documentations to figure out how to add the reference for a new-added information. This step really took me a long time. Lastly, I set up a lead section. I not only found the template for infoBox and insert but also need to organize two paragraphs to briefly introduce my article. Adding a sub-section is much easier than the previous steps I mentioned.

Generally, this is a busy week for CSC. I learned lots of techniques in programming and Wikipedia! Next week we will need to finish programming project, I guess that would be a fun project as well.

Thursday, February 27, 2014

CSC-5 Binary Notation and Wikipedia Assignment

After the first term test and a long reading week, we begin to touch on binary notation in the lectures. Early machines have limited stuff to represent numbers, characters and colours based on 0s and 1s. There are 256 numbers including 0 to represent the numbers. For example:

represent 2:
10
represent 3:
11
represent 4:
100
represent 5:
101
represent 6:
110
represent 7:

111
We can find that the last digit represents whether the number is odd or even. 0 represents even and 1 represents odd. The second last digit is to divided the number by four so and so forth. 
Therefore, we can get a rule that b7:128 b6: 64 b5: 32 b4: 16 b3:8 b2: 4 b1:2 b0:1
So when we can use bits to find out the exact number. For example:
01100110:128*0 +64*1+32*1+16*0+8*0+4*1+2*1+0*1

In reverse, we can transfer exact number into 8-bit binary with two methods.
Represent 104 as an 8-bit binary:
(< 104 128) so start with 0
(>= 104 64) so next bit is 1
(- 104 64): 40
(>= 40 32): so next bit is 1
(-40 32): 8
(< 16 8): so next bit is 0
(>= 8 8): so next bit is 1
(-8 8):0
so 4, 2 and the 1 bit are p
#b01101000

Alternatively get the bit from the right to the left:
104 is even, so right-most bit is 0
(quotient 104 2): 52
even, so next bit is 0
(quotient 52 2): 26
even, so next bit is 0
(quotient 26 2): 13
odd, so next bit is 1
(quotient 13 2): 6
even, so next bit is 0

We can also represents number into characters. In Dr. Racket, if we put #\a, we can find the exact numbers to represent a character.
e.g. integer->char 104 à #\h

Also we can use it to represent colours. (make-color red green blue transparency) There are 0-255 levels. When these mixtures combined, it may make different colours. For example, when we put (255 255 255 0) in the Dr. Racket, we will get the white and transparent colour. In this week's lecture and quiz, we will cover colour list. This is a list that all the colours to make a picture. 

This week, we begin to touch on the second part of the wikipedia assignment. At first, I am quite confident with the assignment. Now, I find that it is difficult for me to create a new sandbox for my assignment. I plan to figure out this by reading the instruction and policy in wikipedia editing page. I will begin to do this as soon as possible and discuss my approaches to figure out the problems I have when I do the assignments in my next post.