2012年12月5日星期三

Last week of csc

    Finally we finish our class and start to prepare for our fanal exam. I study a lot about C language since the first class of csc104. This is the first time that I use Dr. Racket and I have to take courage to face a lot of challenges.I really prove a lot about the usage of Dr. Racket and C language.  I hope that I can study hard for our final exam and get a satisfied score. Thank you, our TA and professor!~~~

2012年11月30日星期五

Project 2

I don't feel too difficult of project 2 but I have to work hard for it. For instance, I have to figure out how to write two more check-expect expressions for strict-interpolate.
(define (strict-interpolate f n1 n2)
  (min (max n1 n2)
       (max (min n1 n2) (interpolate f n1 n2))))
(check-ecpect (strict-interpolate 3/2 0 5) 5)
(check-expect (strict-interpolate 3/2 5 0) 5)


To fix interpolate-color(find the minimum or maximum number),we need to write like that:
(define (interpolate-color f c1 c2) c1)
(make-color (interpolate f (color-red c1) (color-red c2))
            (interpolate f (color-green c1) (color-green c2))
            (interpolate f (color-blue c1) (color-blue c2))
            (interpolate f (color-alpha c1) (color-alpha c2)))


To fix  arrow-event:
fix arrow-event
(define (arrow-event n k)
   (cond [(enqual? k "left") (sub1 n)]
   [(equal? k "right") (add1 n)]
   [else n]))

In  conclusion, it looks like that it is shorter than project 1 but we still need to understand the codes and use them in Dr. Racket.

2012年11月23日星期五

Week 11: wikipedia part 3 "koch" "sprial"

This week we study two main orders: koch and sprial.
For the second part of "koch", we need to write one check-expect
(check-expect (koch-snowflake 2)
(above
(beside
(rotate 60 (koch 2))
(rotate -60 (koch 2)))
(rotate 180 (koch 2))))
Then difine it:
(define (koch-snowflake d)
  (above
   (beside
    (rotate 60 (koch d))
    (rotate -60 (koch d))
 )
   (rotate 180 (koch d))))

For "sprial" ,we need to use substring and string-append to finish it.

We have to understand it and practice more to prepare for the quiz~~@-@

For the third part of wikipedia, I change the grammer and spelling for two articles. It is really hard to find mistakes from wikipedia because it has been changed for a lot of times bu other users.I hope that I can do it well~~

2012年11月16日星期五

week 10: Test 2 and gtree

This week we study hor to wtire the oder about the gthree. Basically, we need to difine tree nodes and small trees. After that we should write the list the labels from a gtree. We also have to noice flatten and depth.
For flatten (just a part of it)
; If L is a list, flatten (un-nest) it, otherwise
; make it a list
(check-expect (flatten 5) (list 5))
(check-expect (flatten L1)
              (list 1 2 3 4 5 6 7 8 9 1 2 3))
For depth( just a part of it)
(check-expect (depth 3) 0)
(check-expect (depth (list 3)) 1)
(check-expect (depth (list 1 (list 2) 3))2)  -----> may test on quiz
;
(define (depth L)
  (cond
    [(not (list? L)) 0]
    [else (add1 (apply max (map depth L)))]))

2012年11月9日星期五

Project 1

    I have few tests this week and  I feel a little bit exhausted...Today is the due day of project one and I still have few things to do. I hioe that I can do it well~~

    I find that the second question of project 1 is really hard for me. We need to fix the definition of clarify-image.It is related to map and map image.  Our TA helped us a little and the solution is
(check-expect (clarify-image (circle 10 "solid" (make-color 250 250 250 255)))
              (circle 10 "solid" (make-color 250 250 250 0)))
;
(define (clarify-image im) (map-image clarify-color im)).
W also need to create two (check-expect ...) expressions for set-up-hand. To make it move , we should write like that:
(check-expect (set-up-hand BAR 90)
               (overlay/align
                "middle" "top"
                (rotate -90 BAR)
                (circle
                 (image-width BAR)
                 "solid"
                 (color 255 255 255 0))))
;
(define (set-up-hand im deg)
  (overlay/align
   "middle" "top"
   (rotate (* -1 deg) im)
   (circle
    (image-height (rotate (* -1 deg) im))
    "solid" (make-color 255 255 255 0))))
 I think I should practice more...

2012年11月3日星期六

Week 8

     For the lecture, we study rot13 as algorithm. For example: what is a really simple rule (or set of rules) for (rot13 c), where c is some character? The answer is if c is in a-m, add 13. It c is in n-z,  sub 13.
     For Dr,Racket, I have to understand some orders, for example: to produce string with characters in opposite order from s
     (check-expect (string-reverse "string") "gnirts")
;
(define (string-reverse s)
  (cond
    [(zero? (string-length s)) s]
    [else (string-append (string-reverse (substring s 1)) (substring s 0 1))]))

Also, I have to figure out how to explain whether it is a palindrome or not. Firstly I have to write two check-expect steps.
(check-expect (palindrome? "aa") true)
(check-expect (palindrome? "ab") false)

Then define
(define (palindrome? s)
  (cond
    [(< (string-length s) 2) true]
    [else
     (and
      (palindrome? (substring s 1 (sub1 (string-length s))))
      (equal? (string-ref s 0) (string-ref s (sub1 (string-length s)))))]))

Now I have to prepare for project 1 because it will due next week.


 


2012年10月27日星期六

Week 7

 For this week's lecture, we study what von neumann looks like, input, output, shorage and the protection from machine.
    We study some simple orders in Dr.Racket.
For example, if we put this oder in Dr.Racket:
; number-hunch : number -> string
; Is n really, really big?
; that is, is it more than 101
(define (number-hunch n)
  (cond
    [(> n 101) "Oh, it's *really* big"]
    [else "Not so big"]))
(number-hunch 5)
(number-hunch 102)
(define (GCD m n)
  (cond
    [(zero? n) m]
    [else (GCD n (remainder m n))]))
(GCD 35 15)
(GCD 15 35)
To run this one, we can get " Not so big" if numer-biunch is 5. The result of both (GCD 35 15) and (GCD 15 35) are 5.