게시판 인덱스

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

늦었지만, 4.1 테스트셋입니다.

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



가입: 2011년 9월 19일
올린 글: 40

올리기올려짐: 2011년10월21일 3:54    주제: 늦었지만, 4.1 테스트셋입니다. 인용과 함께 답변

smatch는 유강민님께서 올려주신 테스트셋 잘 돌아가길래 다 되었구나 하고 있었는데, (매번 정말 고맙습니다. ^^)
"즐거운 고민" 문제를 다 풀고 두 문제 제출 하려다가 게시판에 와보니,
조교님께서 올려주신 "작년의 광범위한 테스트셋"이 새로 있더군요.
그거로 테스트 넣어보니, 역시 내가 짠 코드로구나...ㅠ 하고 좌절을 했습니다.
아 그냥 내지 뭐 하고 잠시 내적 갈등을 겪기도 했는데, 저 테스트셋을 모두 true로 만들어 보자 싶어서 아직도 잠을 안자고 있군요. ㅎ
유강민 님처럼 깔끔하게는 못 만들었지만 그래도 #t가 뜨는지 확인할 수 있도록 앞뒤로 코드 붙인 것 올려봅니다.
전부 true로 도배가 되시길 기원합니다. ^^

코드:
(equal? (smatch (list 1 2 3)
        (dot (dot (atom 1) (atom 2)) (atom 3)))  #t )

(equal? (smatch (list 1 2 3)
        (dot (atom 1) (dot (atom 2) (atom 3))))  #t  )

(equal? (smatch (list 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1)
        (star (star (optional (atom 1)))))  #t  )

(equal? (smatch (list 1 2 3 4 5 6 7 8 9 0)
        (dot
         (dot
          (dot (atom 1) (atom 2))
          (dot (atom 3) (dot (atom 4) (atom 5))))
         (dot
          (dot (atom 6) (atom 7))
          (dot (atom 8) (dot (atom 9) (atom 0))))))  #t  )

(equal? (smatch (list 1)
        (optional (optional (optional (atom 1)))))  #t  )

(equal? (smatch ()
        (optional (optional (optional (atom 1)))))  #t  )

(equal? (smatch (list 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 8 8 9 9)
        (dot
         (dot (star (atom 9)) (star (atom 8)))
         (bar (optional (atom 9)) (star (atom 9)))))  #t  )

(equal? (smatch (list 1 0 0 1 1 2 2 2 2 0 1 0 1 2 2 0 0 1 1 1 1 1 1 2 0 0 0 1 0 1 0 0 1 2 2 2 2)
        (dot (dot (atom 1) (star (bar (bar (star (atom 0)) (star (atom 1))) (star (atom 2))))) (atom 2)))  #t  )

(define c1 (dot (dot (dot (atom 0)
                          (optional (atom 1)))
                     (optional (dot (atom 1)
                                    (atom 0))))
                (dot (optional (bar (dot (atom 3)
                                         (atom 7))
                                    (dot (atom 1)
                                         (atom 0))))
                     (star (dot (star (atom 9))
                                (optional (atom 0)))))))

(equal?  (smatch (list 0) c1)  #t  )

(equal? (smatch (list 0 1) c1)  #t  )

(equal? (smatch (list 0 3 7) c1)  #t  )

(equal? (smatch (list 0 1 1 0 3 7 0 0 0 0 0 0 9 0 9 0 9 9 0) c1)  #t  )

(equal? (smatch (list 0 1 1 0 3 7 1 0 0 0 0 0 0 0) c1)  #f  )

(define c2 (dot (atom 0)
                (star (bar (atom 1)
                           (dot (optional (atom 2))
                                (atom 3))))))

(equal? (smatch (list 0 1 1 1 1 1 1 3 1 1 3 3 1 3 1 3 3) c2)  #t  )

(equal? (smatch (list 0 1 2 3 1 2 3 1 2 3 1 2) c2)  #f  )

(equal? (smatch (list 0 1 1 1 1 1 1 1 2) c2)  #f )

(equal? (smatch (list 1 0 0 1 1 2 2 2 2 0 1 0 1 2 2 0 0 1 1 1 1 1 1 2 0 0 0 1 0 1 0 0 1 2 2 2 1)
        (dot (dot (atom 1) (star (bar (bar (star (atom 0)) (star (atom 1))) (star (atom 2))))) (atom 2)))  #f  )


코드:
(define (compare list1 list2) (if (null? list1) empty (if (equal? (car list1) (car list2)) (cons #t (compare (cdr list1) (cdr list2))) (cons #f (compare (cdr list1) (cdr list2))))))

(define result (list (smatch '(3 4) (atom 4))
(smatch '(0 1) (dot (atom 0) (atom 1)))
(smatch '(0) (bar (atom 0) (atom 1)))
(smatch '(2) (optional (atom 2)))
(smatch '(3 3 3 2) (star (atom 3)))
(smatch '(3 3 3 2) (dot (star (atom 3)) (optional (atom 2))))
(smatch '(2 3 3 2) (dot (optional (atom 2)) (dot (star (atom 3)) (atom 2))))
(smatch '(1 0 1 0 0 1 0 1 1 0) (star (bar (dot (atom 1) (atom 0)) (dot (atom 0) (atom 1)))))
(smatch '(1 0 1 0 0) (star (dot (atom 1) (atom 0))))
(smatch '(0 1 2 3) (bar (dot (optional (atom 0)) (optional (atom 1))) (dot (atom 2) (atom 3))))
(smatch '(1 0 1) (dot (optional (atom 1)) (bar (dot (optional (atom 0)) (optional (atom 1))) (dot (atom 2) (atom 3)))))
(smatch '(9 9 9 9) (dot (optional (atom 9)) (dot (dot (optional (atom 9)) (optional (atom 9))) (optional (atom 9)))))
(smatch '(9 9 9) (dot (optional (atom 9)) (dot (dot (optional (atom 9)) (optional (atom 9))) (optional (atom 9)))))
(smatch '(0 1 0) (dot (dot (optional (atom 0)) (optional (atom 1))) (dot (optional (atom 1)) (optional (atom 0)))))
(smatch '(0 1 0) (dot (atom 0) (bar (dot (optional (atom 0)) (optional (atom 1))) (dot (optional (atom 1)) (optional (atom 0))))))
(smatch '(0 0 0 0 9) (star (optional (atom 0))))
(smatch '(2 3 2 1 0 4) (star (dot (dot (dot (dot (optional (atom 0)) (optional (atom 1))) (optional (atom 2))) (optional (atom 3))) (optional (atom 4)))))
(smatch '(1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2) (dot (star (bar (dot (atom 1) (atom 1)) (atom 1))) (atom 2)))
(smatch '(1 1 1 1 1 1 1 1 1 1 1 1 2) (dot (star (bar (dot (dot (atom 1) (atom 1)) (atom 1)) (bar (dot (atom 1) (atom 1)) (atom 1)))) (atom 2)))
(smatch '(0 0 1 0 0 1 0 1 0 1 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 1 0 0 1 2) (dot (star (bar (bar (dot (atom 0) (atom 1)) (atom 0)) (dot (atom 1) (atom 0)))) (atom 2)))
(smatch '(0) (atom 0))
(smatch '(8 4) (dot (atom 8) (atom 4)))
(smatch '(9 6) (dot (dot (optional (atom 9)) (optional (atom 3))) (dot (optional (atom 6)) (optional (atom 7)))))
(smatch '(1 7) (dot (optional (dot (atom 1) (atom 0))) (dot (atom 1) (atom 7))))
(smatch '(1 1 1 1 1 1 1 1 1) (star (atom 1)))
(map (lambda (x) (smatch x (dot (star (dot (atom 1) (atom 0))) (atom 1)))) '((1 1) (1 0 1) (1 0 1 0 1) (1 0 1 0 2)))
(map (lambda (x) (smatch x (bar (dot (atom 1) (atom 2)) (dot (bar (atom 3) (atom 4)) (atom 5))))) '((1 2) (1 0) (1 3) (1 5) (2 4) (2 5) (3 4) (3 5) (4 5) (6 8 9)))
(map (lambda (x) (smatch x (dot (star (dot (optional (atom 7)) (optional (atom 5)))) (star (atom 4))))) '((7 5 4) (7 7 5 7 5 5 5 5 4 4) (7 4 5 4) (5 7 5 4) (5 7 4) (4 4 4) (3 1 9 2) (7 7 4)))
(map (lambda (x) (smatch x (dot (star (dot (atom 7) (optional (atom 5)))) (star (atom 4))))) '((7 5 4) (7 7 5 7 5 5 5 5 4 4) (7 4 5 4) (5 7 5 4) (5 7 4) (4 4 4) (3 1 9 2) (7 7 4)))
(map (lambda (x) (smatch x (dot (dot (bar (atom 1) (optional (atom 3))) (bar (atom 5) (atom 7))) (dot (bar (atom 2) (atom 4)) (bar (atom 6) (atom 8)))))) '((1 2 3 4) (1 3 2 4) (1 5 2 6) (3 5 4 6) (3 7 6 4) (1 7 2 8)))
(map (lambda (x) (smatch x (dot (dot (dot (atom 1) (atom 2)) (dot (atom 1) (atom 2))) (dot (dot (atom 1) (atom 2)) (dot (atom 1) (atom 2)))))) '((1 2) (1 2 1 2) (1 2 1 2 1 2) (1 2 1 2 1 2 1 2) (1 2 1 2 1 2 1 2 1 2) (1 1 1 1 2 2 2 2)))
(smatch '(1 4) (dot (if (smatch '(1 9) (dot (atom 1) (atom 9))) (atom 1) (atom 2)) (if (smatch '(1) (dot (optional (atom 1)) (atom 3))) (atom 7) (bar (star (atom 4)) (dot (atom 4) (atom 1))))))
(smatch '(1 1 1 1 1 4 4) (dot (dot (star (de-optional (optional (de-dot-0 (dot (atom 1) (atom 2)))))) (optional (dot (atom 4) (optional (de-bar-1 (bar (atom 9) (atom 3))))))) (de-dot-0 (dot (bar (atom 1) (star (atom 4))) (dot (atom 7) (de-star (star (atom 2))))))))
(map (lambda (x) (smatch x (dot (star (atom (+ (de-atom (list-ref (list (atom 0) (atom 5) (atom 8)) 1)) (de-atom (de-dot-0 (de-bar-1 (bar (dot (atom 2) (atom 3)) (dot (atom 1) (atom 4))))))))) (atom (* (de-atom (cadr (list (atom 1) (atom 2) (atom 3)))) (de-atom (de-bar-0 (de-dot-1 (de-dot-1 (dot (de-star (star (dot (atom 2) (atom 3)))) (de-optional (optional (dot (atom 1) (bar (atom 4) (atom 3))))))))))))))) '((1 3 3) (8 8 6) (5) (2 9) (3 9) (6 6 8) (1 7) (3 6) (8)))
(map (lambda (x) (smatch x (dot (dot (dot (dot (atom 1) (optional (atom 2))) (dot (optional (atom 3)) (optional (atom 4)))) (dot (dot (optional (atom 5)) (optional (atom 6))) (dot (optional (atom 7)) (optional (atom 8))))) (dot (star (atom 9)) (atom 0))))) '((1 9) (1) (0) (1 0) (1 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 0) (1 2 9 0 1 3 4 9 9 0 1 5 6 7 9 9 9 0 1 8 9 2 3 9 9 9 9 0 1 4 5 6 7 8 9 9 9 9 9 0 1 0) (1 4 9 4 0) (1 5 0 1 9 9 0) (1 2 2 0) (1 4 1 4 0 0))) ))

(define correct (list #f  #t  #t  #t  #f  #t  #t  #t  #f  #f  #t  #t  #t  #t  #t  #f  #t  #t  #t  #t  #t  #t  #t  #t  #t
'(#f #t #t #f)
'(#t #f #f #f #f #f #f #t #t #f)
'(#t #t #f #t #t #t #f #t)
'(#t #f #f #f #f #t #f #t)
'(#f #f #t #t #f #t)
'(#f #f #f #t #f #f)  #t  #t
'(#f #f #f #f #f #t #f #f #t)
'(#f #f #f #t #t #f #f #f #f #f) ))

(compare result correct)
[/quote]

방정호 가 2011년10월21일 10:39에 수정함, 총 1 번 수정됨
위로
사용자 정보 보기 비밀 메시지 보내기
이태영



가입: 2011년 9월 19일
올린 글: 34

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

감사합니다^_^
위로
사용자 정보 보기 비밀 메시지 보내기 이메일 보내기
이전 글 표시:   
이 게시판은 잠겼으므로 글을 올리거나, 답변을 하거나 수정을 할 수 없습니다   이 주제는 잠겼으므로 답변을 하거나 수정을 할 수 없습니다     게시판 인덱스 -> 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