Wednesday 28 November 2012

Week 12: Project 2

In this post, I am going to talk about the things I have learnt and problems that I encountered in the Project 2.

1. min and max

This function is about finding the smaller or bigger number from the list.
For example,
(min 10 5)
>5
(max 10 100)
>100
I was not so sure about this function before I looked it up in the textbook.



 2. interpolate-color

The function "strict-interpolate" was not hard to understand, it is just about calculating the number with "interpolate" and then finding the minimum or maximum number.
I got stuck on putting two functions together on "interpolate-color".
This time it's not about using "map" or "map-image", I tried things like


(define (interpolate-color f c1 c2) (make-color
                                 (color-red (strict-interpolate f c1 c2))
                                 (color-green (strict-interpolate f c1 c2))
                                 (color-blue (strict-interpolate f c1 c2))
                                 255))
(define (interpolate-color f c1 c2) (make-color
                                 (color-red (strict-interpolate f (color-red c1) (color-red c2)))
                                 (color-green (strict-interpolate f (color-green c1) (color-green c2)))
                                 (color-blue (strict-interpolate f (color-blue c1) (color-blue c2)))
                                 255)) 

However, it is actually like this

(define (interpolate-color f c1 c2)
  (make-color (strict-interpolate f (color-red c1)(color-red c2))
              (strict-interpolate f (color-green c1)(color-green c2))
              (strict-interpolate f (color-blue c1)(color-blue c2))
              (strict-interpolate f (color-alpha c1)(color-alpha c2))))


2.  arrow-event

By studying these "check-expects",

(check-expect (arrow-event 3 "left") 2)
(check-expect (arrow-event 3 "right") 4)
(check-expect (arrow-event 3 "up") 3)

I fixed the function by referring the recursion exercises, at last I got it working.

(define (arrow-event n k)
  (cond
    [(equal? k "left")(- n 1)]
    [(equal? k "right")(+ n 1)]
    [else n]))


In conclusion, this project is seemed to be shorter than project 1; however, this is not really a piece of cake for me. Without doubt, this project as well involves lots of thinking and understanding of the usage of codes.


Friday 23 November 2012

Week 11: Wikipedia Project

1. Understanding the Problem

To start the Wikipeadia Project, I have registered an account (user: Tiffanylo1202) and looked up some small projects needing work on Wikipedia. I have picked three Wikipedia articles to work on, these are the links:

http://en.wikipedia.org/wiki/Nicole_Abe
http://en.wikipedia.org/wiki/Kiss_the_Girls_(1965_film)
http://en.wikipedia.org/wiki/Yeong-gam


I am asked to translate and improve the work of these articles.




2. Devising a Plan

I have selected to three articles to translate; from the codes, I have noticed that the articles are roughly translated from Japanese, Korean and Greek to English. In order to edit the articles properly and enhance its quality and fluency, it is better for me to reword the translations and use dictionaries as a tool.

Before I help out with translating the articles, I should check whether the articles are mere copies of an article in a foreign-language Wikipedia. If any of them is a mere copy, I will just tag it with {{db-foreign}} to add it to “Wikipedia: Candidates for speedy deletion”.

When I start translating the articles, I should be aware that the translations are written in Manual of style (MOS) and keeping the writing clear and concise.

I have also noticed that I might somehow contribute by adding a translation from the original translation to another foreign language at a Wikipedia in that foreign language after the translation. Besides, it might also be great to become a part of “Wikipedia’s effort to coordinate across different languages”.


3. Carrying out the Plan

I have started working on the articles. I used different electronic resources/tools to understand the original texts of the articles. To be more accurate, I looked up the references and added more related information to the articles with proper translation. I as well deleted some false statements from the articles.


4. Looking back

After I have got these three articles altered, I read and went through the articles again in order to ensure the language is translated properly and there is no more mistakes.


Wednesday 21 November 2012

Week 11: The Snowflake

It's all about recursion this week.
The rkt. files spiral and koch are about doing the same thing.

For koch, it is a function to make the 1/3 of a snowflake.
Here's the function,

(define (koch d)
  (cond
    [(zero? d) (line 5 0 "blue")]
    [else
     (beside/align
      "bottom"
      (koch (sub1 d))
      (rotate 60 (koch (sub1 d)))
      (rotate -60 (koch (sub1 d)))
      (koch (sub1 d)))]))
These are two of the outcomes,

(koch 0)
_
As d=0, when (zero? 0), a blue line (5) shows up.

(koch 1)
_/\_
As d=1, it goes to [else ...], when it goes to (koch (sub1 1)), it goes back to (koch 0), which is a blue line.


After "koch", it's followed by "koch-snowflake"
Here's the function,


(define (koch-snowflake d)
  (above
   (beside
    (rotate 60 (koch d))
    (rotate -60 (koch d)))
   (rotate 180 (koch d))))


It forms a complete snowflake by putting three "koches" (three 1/3 of a snowflake) together like a triangle.
It is fun when I trying to imagine the output by myself before checking it with DrRacket.


Wednesday 14 November 2012

Week 10: Tree and Depth

It is really hard for me to visualize the tree diagram; however, I think it's a bit easier to understand by writing the things down step by step.

There is a few important functions being used in this tree diagram section.

1. structure of genetic tree
(define-struct gtree (label left right))
2. the branches - defining the leaves
(define leaf1 (make-gtree "ACTG" empty empty))
3. defining the small trees
(define tree1 (make-gtree "AAA" leaf1 leaf2)) 
4.  to "harvest" the tree (knowing the branches). This is an example of recursion.

(define (harvest G)
  (cond
    [(not (gtree? G)) empty]
    [else
     (append
      (list (gtree-label G))
      (harvest (gtree-left G))
      (harvest (gtree-right G)))]))
It as well took me a while to understand the function "depth".
However, it is easier to interpret if you think it as counting for different layers.


(define (depth L)
  (cond
    [(not (list? L)) 0]
    [else (add1 (apply max (map depth L)))]))
For example,
(check-expect (depth (list 1 (list 2) 3))  2)
list 1 and 3 --> 1
list 2 --> 1
total = 2

Recursion is not a really hard chapter, yet, it takes one lots of time to understand or figure out what's happening, it is just complicated sometimes and one can get confused or lost very easily.

Wednesday 7 November 2012

Week 9: Project 1

In this post, I am going to talk about the things I have learnt and problems that I encountered in the Project 1. Before I started working on this project, I was not that familiar with the codes; however, this project indeed helped me on giving me a better insight of different functions.

1. About "make-color"

(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)])))


I have to make a "check-expect" basing on the above,
at first I tried putting the entire function "(make-color 1 2 3 0)" to c.
However, this can actually be done very easily.

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


2.  Clarify-image

I got stuck for more than 4 hours on fixing the function "clarify-image".
After looking back and working on the previous exercise "map and map-image", I got this function working finally!

An example from the exercise "mapping",

(map-image less-green "pic: hacker")

To define a function by using another function, which is the "clarify-color", I had to use the "map-image".
Here is what I did at last,

(define (clarify-image im) (map-image clarify-color im))


3.  Set-clock

After fixing the function "set-clock",

(define (set-clock h m s s/g) (make-clocktime h m s s/g))

I had to make two "check-expect" for the function.
It might somehow seem easy for the others after they've looked at your work;
however, to have every next function working fine, you always have to trace back and truly understand every steps.

Without studying the above functions, you might not know h=hours, m=minutes, s=seconds, s/g=STOP/GO;
and you as well might not know what "make-clocktime" is.
This is one of the check expect,

(check-expect (set-clock 6 7 8 STOP) (make-clocktime 6 7 8 STOP))


4. check-key

I had to fix the function "check-key" by following the hints from the "check-expect".
I had spent quite a while on this as I was so confused about what to do with the last section "s/g".

But at last, I found that it could actually be done very simply, it's just that I had been thinking in a too complicated way.

(check-expect (check-key (make-clocktime 1 2 3 GO) "down") (make-clocktime 1 2 3 STOP))
(define (check-key c k)
  (cond
    [(equal? k "down")
     (make-clocktime
   (clocktime-hours c)
   (clocktime-minutes c)
   (clocktime-seconds c)
   STOP)]
    [else c]))


To sum up, I think I have learnt a lot after doing the project. It is just kind of like a revision, helping clarifying everything we have been learning.


Wednesday 31 October 2012

Week 8: About the String Functions


We had to go through the text ourselves and try out the string functions. I found it challenging as these few weeks we have to compose the codes ourselves.

I firstly practiced with the basic codes in order to revise the following three functions:
1. substring
>(substring "tiffany" 0 4)
tiff
2. string-append
>(string-append "tiffany" "is" "a" "good" "girl")
tiffanyisagoodgirl

3. string-length
>(string-length "tiffany")
7
I started working on the tutorial handout afterwards. These are what I got after spending more than an hour on DrRacket.

(define (repeat word)(string-append word word))  
(define (chop-first-char xxx)(substring xxx 1)) 
(define (first-char x)(substring x 0 1)) 
(define (last-half xxxx)(substring xxxx
                                   (round (* 1/2 (string-length xxxx)))))
                                     
(define (first-half xxxx)(substring xxxx 0
                                   (round (* 1/2 (string-length xxxx)))))

these are the outputs:

>(repeat word "tiff")
tifftiff 
>(chop-first-char "tiff")
iff
>(first-char "tiff")
>(last-half "tiff")
ff 
>(first-half "tifff")
ti

This exercise indeed required me think a lot and undoubtedly, a complete understanding of the codes.




                     

Wednesday 24 October 2012

Week 7: If-else Statements and GCD

This week, I've learned about the if-else statements and the build-in function GCD.

For the conditional statement, I've tried to define some with it.
For example, defining a number greater than 500 as big,

(define (bigger-number n)
  (cond
    [(> n 500) "big"]
    [else "Not too big"])) 

(check-expect (bigger-number 30) Not too big)
(check-expect (bigger-number 555) big)



The greatest common divisor (GCD) of two non-negative integers (whole numbers) is a non-negative integer that
  1. divides both numbers, and
  2. is the largest non-negative number that does so.

For the GCD funtion, here are some examples,

(GCD 2 10)
>2
(GCD 100 10)
>10
It is so much easier and convenient when you can find the GCD on the computer.