이전 주제 보기 :: 다음 주제 보기 |
글쓴이 |
메시지 |
최원태
가입: 2006년 9월 16일 올린 글: 369
|
올려짐: 2008년9월12일 14:47 주제: 숙제1에 대한 안내 <- 내용이 계속 추가됩니다. |
|
|
1.
2친구 덧셈을 구현할 때, 내부적으로 10진수로 변환하시면 안됩니다.
2친수 자체의 구조를 잘 생각해서 재귀적으로 작성해주세요.
2.
scheme 표준을 지켜주세요.
비표준을 사용하면 과제가 채점시스템에서 실행되지 않을지도 모릅니다.
최원태 가 2008년9월25일 20:10에 수정함, 총 2 번 수정됨 |
|
위로 |
|
|
정영범
가입: 2005년 9월 5일 올린 글: 167
|
올려짐: 2008년9월12일 16:04 주제: Re: List 다루기 |
|
|
List를 다루는 프로그램 예제입니다.
아래 코드를 긁어다 Dr Scheme에서 직접 실행시켜 보시고, 이해하시기 바랍니다.
사실 책에 다 나와있는 내용이니 모르시는 것이 있으면 교재 2.2를 참조하세요.
코드: |
;; defining lists
(define list1 '(1 3 5))
(cons 7 list1)
(car list1)
(cdr list1)
(define list2 (list 2 4 6))
(define slist (list "kwang" "won" "yung"))
(display "-------1-------\n")
;; append two lists
;; append_list : a list -> a list -> a list
(define (append_list list1 list2)
(if (null? list1)
list2
(cons (car list1)
(append (cdr list1) list2))))
(define biglist (append_list list1 list2))
biglist
(append_list list1 slist)
(display "-------2-------\n")
;; list map
;; map_list : (a -> b) -> a list -> b list
(define (map_list f lst)
(if (null? lst)
null
(cons (f (car lst))
(map_list f (cdr lst)))))
(define (double x) (* x 2))
(map_list double biglist)
(display "-------3-------\n")
;; filtering list
;; filter_list : (a -> bool) -> a list -> a list
(define (filter_list f lst)
(cond ((null? lst) null)
((f (car lst)) (cons (car lst)
(filter_list f (cdr lst))))
(else (filter_list f (cdr lst)))))
(filter_list even? biglist)
(filter_list (lambda (x) (> x 3)) biglist)
|
|
|
위로 |
|
|
정영범
가입: 2005년 9월 5일 올린 글: 167
|
올려짐: 2008년9월17일 20:52 주제: |
|
|
숙제 5의 nth-child 문제 0을 넣으면 첫번째 원소를 돌려주게 만드세요.
n>=0 인 가정하에 n은 n+1번째 나무를 내 놓으면 됩니다. |
|
위로 |
|
|
정영범
가입: 2005년 9월 5일 올린 글: 167
|
올려짐: 2008년9월17일 22:06 주제: |
|
|
숙제 6번의 간단한 test code입니다.
코드: |
(define model1 (model 1))
(define model2 (model 2))
(define model3 (model 3))
(define model4 (model 4))
(define branch1 (make-branch 10 model1))
(define branch2 (make-branch 20 model2))
(define mobile1 (make-mobile branch1 branch2))
(define branch3 (make-branch 20 model3))
(define branch4 (make-branch 15 model4))
(define mobile2 (make-mobile branch3 branch4))
(define big-mobile
(make-mobile (make-branch 10 mobile1)
(make-branch 30 mobile2)))
mobile1
mobile2
big-mobile
(weight mobile1)
(weight mobile2)
(weight big-mobile)
(is-balanced? mobile1)
(is-balanced? mobile2)
(is-balanced? big-mobile)
|
|
|
위로 |
|
|
|