게시판 인덱스

 
 FAQFAQ   검색검색   멤버리스트멤버리스트   사용자 그룹사용자 그룹   사용자 등록하기사용자 등록하기 
 개인 정보개인 정보   비공개 메시지를 확인하려면 로그인하십시오비공개 메시지를 확인하려면 로그인하십시오   로그인로그인 

숙제4 테스트셋입니다

 
이 게시판은 잠겼으므로 글을 올리거나, 답변을 하거나 수정을 할 수 없습니다   이 주제는 잠겼으므로 답변을 하거나 수정을 할 수 없습니다     게시판 인덱스 -> 4190.210 Principles of Programming (Fall 2011)
이전 주제 보기 :: 다음 주제 보기  
글쓴이 메시지
유.강민



가입: 2011년 3월 22일
올린 글: 38

올리기올려짐: 2011년10월14일 17:03    주제: 숙제4 테스트셋입니다 인용과 함께 답변

검색했는데 없어서 직접 만든거 올립니다
문제있으면 지적해주세요

코드:

;4-1
(define (_m n b ans)
   (cond ((equal? b ans) (begin (display "success: #") (display n) (newline)))
         (else (begin (display "failure: #") (display n) (newline)))))

(_m 0 (smatch (list 1 1) (dot (dot (atom 1) (star (atom 0))) (atom 1))) #t)
(_m 1 (smatch (list 3 4) (dot (atom 3) (atom 4))) #t)
(_m 2 (smatch (list 4 3 3) (dot (atom 4) (star (atom 3)))) #t)
(_m 3 (smatch (list 5 5 5) (star (atom 5))) #t)
(_m 4 (smatch (list 6) (bar (atom 3) (atom 6))) #t)
(_m 5 (smatch (list 7 9) (dot (bar (atom 7) (atom 9)) (bar (atom 8) (atom 9)))) #t)
(_m 6 (smatch (list 1 1) (dot (star (dot (atom 1) (atom 0))) (atom 1))) #f)
(_m 7 (smatch (list 1 0 1 0 1 0 1) (dot (star (dot (atom 1) (atom 0))) (atom 1))) #t)
(_m 8 (smatch (list 8) (dot (dot (optional (atom 3)) (atom 8)) (star (dot (dot (atom 3) (atom 8)) (atom 3))))) #t)
(_m 9 (smatch (list 3 8) (dot (dot (optional (atom 3)) (atom 8)) (star (dot (dot (atom 3) (atom 8)) (atom 3))))) #t)
(_m 10 (smatch (list 3 8) (dot (dot (optional (atom 3)) (atom 8)) (star (dot (dot (atom 3) (atom 8)) (atom 3))))) #t)
(_m 11 (smatch (list 3 8) (dot (optional (atom 3)) (atom 8))) #t)
(_m 12 (smatch (list 8) (dot (optional (atom 3)) (atom 8))) #t)
(_m 13 (smatch (list 4 8) (dot (optional (atom 3)) (atom 8))) #f)

(_m 14 (smatch (list ) (star (star (star (star (bar (dot (atom 5) (atom 6)) (dot (atom 9) (atom 1)))))))) #t)
(_m 15 (smatch (list 5 6 5 6 5 6 5 6 9 1) (star (star (star (star (bar (dot (atom 5) (atom 6)) (dot (atom 9) (atom 1)))))))) #t)
(_m 15 (smatch (list 5 6 5 6 5 6 5 6 9 1) (bar (star (star (star (star (dot (atom 5) (atom 6)))))) (star (star (star (star (dot (atom 9) (atom 1)))))))) #f)

(define anynum (bar (bar (bar (bar (bar (bar (bar (bar (bar (atom 0) (atom 1)) (atom 2)) (atom 3)) (atom 4)) (atom 5)) (atom 6)) (atom 7)) (atom 8)) (atom 9)))
(define anynum_except0 (bar (bar (bar (bar (bar (bar (bar (bar (atom 1) (atom 2)) (atom 3)) (atom 4)) (atom 5)) (atom 6)) (atom 7)) (atom 8)) (atom 9)))
(define anynum_except9 (bar (bar (bar (bar (bar (bar (bar (bar (atom 0) (atom 1)) (atom 2)) (atom 3)) (atom 4)) (atom 5)) (atom 6)) (atom 7)) (atom 8)))
(define birthday_nolaterthan2011_butdontcarefeb29 (dot
                                                   (bar
                                                    (dot
                                                     (dot (atom 1) (atom 9))
                                                     (dot anynum anynum))
                                                    (dot
                                                     (dot (atom 2) (atom 0))
                                                     (bar
                                                      (dot (atom 0) anynum)
                                                      (dot (atom 1) (bar (atom 0) (atom 1))))))
                                                   (bar
                                                    (bar
                                                     (dot
                                                      (bar
                                                       (bar
                                                        (bar
                                                         (bar
                                                          (bar
                                                           (bar
                                                            (dot (atom 0) (atom 1))
                                                            (dot (atom 0) (atom 3)))
                                                           (dot (atom 0) (atom 5)))
                                                          (dot (atom 0) (atom 7)))
                                                         (dot (atom 0) (atom 8)))
                                                        (dot (atom 1) (atom 0)))
                                                       (dot (atom 1) (atom 2)))
                                                      (bar
                                                       (bar
                                                        (dot (atom 0) anynum_except0)
                                                        (dot (bar (atom 1) (atom 2)) anynum))
                                                       (dot (atom 3) (bar (atom 0) (atom 1)))))
                                                     (dot
                                                      (bar
                                                       (bar
                                                        (bar
                                                         (dot (atom 0) (atom 4))
                                                         (dot (atom 0) (atom 6)))
                                                        (dot (atom 0) (atom 9)))
                                                       (dot (atom 1) (atom 1)))
                                                      (bar
                                                       (bar
                                                        (dot (atom 0) anynum_except0)
                                                        (dot (bar (atom 1) (atom 2)) anynum))
                                                       (dot (atom 3) (atom 0)))))
                                                    (dot
                                                     (dot (atom 0) (atom 2))
                                                     (bar
                                                      (bar
                                                       (dot (atom 0) anynum_except0)
                                                       (dot (atom 1) anynum))
                                                      (dot (atom 2) anynum_except9))))))
(_m 16 (smatch (list 1 9 9 0 1 0 2 7) birthday_nolaterthan2011_butdontcarefeb29) #t)
(_m 17 (smatch (list 2 0 1 2 1 0 2 7) birthday_nolaterthan2011_butdontcarefeb29) #f)
(_m 18 (smatch (list 2 0 1 1 1 3 3 0) birthday_nolaterthan2011_butdontcarefeb29) #f)
(_m 19 (smatch (list 2 0 1 1 0 4 3 1) birthday_nolaterthan2011_butdontcarefeb29) #f)
(_m 20 (smatch (list 1 8 9 9 0 2 2 8) birthday_nolaterthan2011_butdontcarefeb29) #f)
(_m 21 (smatch (list 2 0 0 1 0 9 1 1) birthday_nolaterthan2011_butdontcarefeb29) #t)

(define _pattern (list 3 6 9))
(define (_iter pat n)
  (cond ((= n 0) pat)
        (else
         (append pat (_iter pat (- n 1))))))
(_m 22 (smatch (_iter _pattern 1000) (star (dot (dot (atom 3) (atom 6)) (atom 9)))) #t)



;4-2
(define (_equal a b)
  (define (element? x lst)
    (cond ((null? lst) #f)
          ((_equal x (car lst)) #t)
          (else (element? x (cdr lst)))))
  (define (intersect a b)
    (if (null? a) '()
        (let ((included (element? (car a) b)))
          (if (null? (cdr a))
              (if included a '())
              (if included
                  (cons (car a) (intersect (cdr a) b))
                  (intersect (cdr a) b))))))
  (cond ((and (list? a) (list? b))
         (= (length (intersect a b)) (length a) (length b)))
        (else
         (equal? a b))))

(define (_m n b ans)
   (cond ((_equal b ans) (begin (display "success: #") (display n) (newline)))
         (else (begin (display "failure: #") (display n) (newline)))))

(_m 0 (shoppingList (list (cons 'A (mustAnd (mustItems (list 1 2))
                                            (mustHaveCommon (mustBeTheSame 'B)
                                                            (mustBeTheSame 'C))))
                          (cons 'B (mustHaveCommon (mustBeTheSame'C)
                                                   (mustItems (list 2 3))))
                          (cons 'C (mustAnd (mustItems (list 1))
                                            (mustHaveExceptFor (mustBeTheSame 'A)
                                                               (list 3))))))
    (list (cons 'A (list 1 2))
          (cons 'B (list 2))
          (cons 'C (list 1 2))))
(_m 1 (shoppingList (list (cons 'A (mustAnd (mustHaveExceptFor (mustBeTheSame 'B)
                                                               (list 1 2))
                                            (mustItems (list 3))))
                          (cons 'B (mustHaveCommon (mustBeTheSame 'A)
                                                   (mustBeTheSame 'C)))
                          (cons 'C (mustAnd (mustItems (list 4 5))
                                            (mustBeTheSame 'A)))))
    (list (cons 'A (list 3))
          (cons 'B (list 3))
          (cons 'C (list 3 4 5))))
(_m 2 (shoppingList (list (cons 'A (mustAnd (mustHaveExceptFor (mustBeTheSame 'B)
                                                               (list 1 2))
                                            (mustItems (list 3))))
                          (cons 'B (mustHaveCommon (mustBeTheSame 'A)
                                                   (mustBeTheSame 'C)))
                          (cons 'C (mustAnd (mustItems (list 2 3))
                                            (mustBeTheSame 'A)))))
    (list (cons 'A (list 3))
          (cons 'B (list 3))
          (cons 'C (list 2 3))))
(_m 3 (shoppingList (list (cons 'A (mustAnd (mustBeTheSame 'B)
                                            (mustBeTheSame 'C)))
                          (cons 'B (mustAnd (mustBeTheSame 'A)
                                            (mustBeTheSame 'C)))
                          (cons 'C (mustAnd (mustBeTheSame 'A)
                                            (mustBeTheSame 'B)))
                          (cons 'D (mustHaveExceptFor (mustItems (list 1 2 3 4))
                                                      (list 3 4)))))
    (list (cons 'A (list ))
          (cons 'B (list ))
          (cons 'C (list ))
          (cons 'D (list 1 2))))
(_m 4 (shoppingList (list (cons 'A (mustBeTheSame 'A))
                          (cons 'B (mustBeTheSame 'B))
                          (cons 'C (mustBeTheSame 'C))))
    (list (cons 'A (list ))
          (cons 'B (list ))
          (cons 'C (list ))))
(_m 5 (shoppingList (list (cons 'A (mustAnd (mustHaveExceptFor (mustAnd (mustBeTheSame 'B)
                                                                        (mustItems (list 1 2 3)))
                                                               (list 4 5))
                                            (mustBeTheSame 'D)))
                          (cons 'B (mustAnd (mustHaveCommon (mustHaveExceptFor (mustHaveCommon (mustBeTheSame 'A)
                                                                                            (mustBeTheSame 'B))
                                                                            (list 2))
                                                            (mustBeTheSame 'C))
                                            (mustItems (list 3 4))))
                          (cons 'C (mustAnd (mustAnd (mustBeTheSame 'D)
                                                     (mustItems (list 1 5)))
                                            (mustBeTheSame 'B)))
                          (cons 'D (mustHaveCommon (mustBeTheSame 'E)
                                                   (mustHaveExceptFor (mustAnd (mustAnd (mustBeTheSame 'A)
                                                                                        (mustBeTheSame 'B))
                                                                               (mustBeTheSame 'C))
                                                                      (list 1 2))))
                          (cons 'E (mustHaveCommon (mustBeTheSame 'A)
                                                   (mustBeTheSame 'B)))))
    (list (cons 'A (list 1 2 3))
          (cons 'B (list 3 4))
          (cons 'C (list 1 3 4 5))
          (cons 'D (list 3))
          (cons 'E (list 3))))
(_m 6 (shoppingList (list ))
    (list ))
(_m 7 (shoppingList (list (cons 'A (mustItems '()))))
    (list (cons 'A (list ))))
(_m 8 (shoppingList (list (cons 'A (mustAnd (mustItems (list 1 2 3))
                                            (mustBeTheSame 'B)))
                          (cons 'B (mustItems (list 1 2 3)))))
    (list (cons 'A (list 1 2 3))
          (cons 'B (list 1 2 3))))
(_m 9 (shoppingList (list (cons 'A (mustItems (list 1 1 1)))))
    (list (cons 'A (list 1))))


유.강민 가 2011년10월20일 0:22에 수정함, 총 1 번 수정됨
위로
사용자 정보 보기 비밀 메시지 보내기
안준형



가입: 2011년 9월 7일
올린 글: 18

올리기올려짐: 2011년10월15일 12:45    주제: 1번 문제 테스트셋 m-6번이요 인용과 함께 답변

(smatch (list 1 1) (dot (star (dot (atom 1) (atom 0))) (atom 1)))

이건데 오른족 식 풀이해보면

(dot (star {0, 1, (10)}) (atom 1))
=
(dot {0*, 1*, (10)*} (atom 1))
=
{0*, 1*, (10)*, (0)*1, (10)*1} 이니까 11 이면 #t아닌가요~?
위로
사용자 정보 보기 비밀 메시지 보내기
김인섭



가입: 2011년 9월 27일
올린 글: 12

올리기올려짐: 2011년10월15일 14:59    주제: m-6번 인용과 함께 답변

(smatch (list 1 1) (dot (star (dot (atom 1) (atom 0))) (atom 1)))

면 (10)*1이죠.. 11이면 #f
위로
사용자 정보 보기 비밀 메시지 보내기
이승중



가입: 2010년 6월 22일
올린 글: 561

올리기올려짐: 2011년10월15일 22:05    주제: 인용과 함께 답변

항상 수고가 많으십니다 Smile
위로
사용자 정보 보기 비밀 메시지 보내기
안준형



가입: 2011년 9월 7일
올린 글: 18

올리기올려짐: 2011년10월17일 14:36    주제: 테스트셋 4-2번에 m3 m4번 인용과 함께 답변

차례대로 값이 ((D 1 2)) 와 ()가 나오는데 이게 틀린 건가요~??
위로
사용자 정보 보기 비밀 메시지 보내기
안준형



가입: 2011년 9월 7일
올린 글: 18

올리기올려짐: 2011년10월17일 14:38    주제: 테스트셋 4-2번에 m3 m4번 인용과 함께 답변

차례대로 값이 ((D 1 2)) 와 ()가 나오는데 이게 틀린 건가요~??

빈 선물들을 (A) (B) 와 같이 표시해야하나요???
위로
사용자 정보 보기 비밀 메시지 보내기
이승중



가입: 2010년 6월 22일
올린 글: 561

올리기올려짐: 2011년10월20일 20:51    주제: 인용과 함께 답변

작년의 광범위한 테스트셋입니다.

https://ropas.snu.ac.kr/phpbb/viewtopic.php?t=2381

https://ropas.snu.ac.kr/phpbb/viewtopic.php?t=2382

숙제 재미있게 하세요..
위로
사용자 정보 보기 비밀 메시지 보내기
이전 글 표시:   
이 게시판은 잠겼으므로 글을 올리거나, 답변을 하거나 수정을 할 수 없습니다   이 주제는 잠겼으므로 답변을 하거나 수정을 할 수 없습니다     게시판 인덱스 -> 4190.210 Principles of Programming (Fall 2011) 시간대: GMT + 9 시간(한국)
페이지 11

 
건너뛰기:  
새로운 주제를 올릴 수 없습니다
답글을 올릴 수 없습니다
주제를 수정할 수 없습니다
올린 글을 삭제할 수 없습니다
투표를 할 수 없습니다


Powered by phpBB 2.0.21-7 (Debian) © 2001, 2005 phpBB Group
Translated by kss & drssay