이글루스 | 로그인  


SICP Exercise 연습문제 3.4

이 문제는 연습문제 3.3에서 만든 프로시저를 수정하여

어떤 이가 암호를 일곱 번 넘게 틀린다면 "call-the-cops"라는 말이 떠야합니다.

 

c4

잘 되는군요.^^

 

이 프로시저의 단점이 있습니다.

연속이냐 불연속이냐 상관없이 무조건 7번 틀리면 경찰을 부릅니다.

 

c5

우리은행 인터넷뱅킹 이용약관

 

우리은행의 경우 비밀번호를 연속으로 틀릴 때 제한을 받습니다.

물론 OTP카드의 경우 총 10회이기는 합니다.

 

이런 부분까지 만들까 생각했지만 7번이면 기회가 많은 듯싶습니다.^^

 

 

참조

해럴드 애빌슨, 김재우 역, <컴퓨터 프로그램의 구조와 해석>, 인사이트, 2007, pp. 295

 

 

; answer
(define (make-account balance password)
  (let ((pw-wrong-count 0))
    (define (withdraw amount)
      (if (>= balance amount)
          (begin (set! balance (- balance amount))
                 balance)
          "Insufficient funds"))
    (define (deposit amount)
      (set! balance (+ balance amount))
      balance)
    (define (dispatch pw m)
      (if (eq? pw password)
          (cond ((eq? m 'withdraw) withdraw)
                ((eq? m 'deposit) deposit)
                (else (error "Unknown request -- MAKE-ACCOUNT"
                             m)))
          wrongpw))
    (define (wrongpw amount)
      (if (< pw-wrong-count 6)
          (begin (set! pw-wrong-count (+ pw-wrong-count 1))
                 "Incorrect password")
          "call-the-cops"))
    dispatch))

; execute
(define acc (make-account 100 'secret-password))
((acc 'secret-password 'withdraw) 40)
((acc 'some-other-password 'deposit) 50)
((acc 'some-other-password 'deposit) 50)
((acc 'some-other-password 'deposit) 50)
((acc 'some-other-password 'deposit) 50)
((acc 'some-other-password 'deposit) 50)
((acc 'some-other-password 'deposit) 50)
((acc 'some-other-password 'deposit) 50)

by | 2008/03/08 19:08 | in OCW | 트랙백 | 덧글(0)

트랙백 주소 : http://NoSyu.egloos.com/tb/4208971
☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]

:         :

:

비공개 덧글

◀ 이전 페이지          다음 페이지 ▶