[인공지능] 선교사와 식인종 문제를 Lisp으로 프로그램하기
- 최초 등록일
- 2004.04.14
- 최종 저작일
- 2004.04
- 4페이지/ 한컴오피스
- 가격 1,000원
목차
3명의 선교사와 3명의 식인종이 강 한쪽에 있다. 그들은 모두 강 반대편으로 건너 가려 하지만 선교사는 식인종이 그들을 해치지 않으리라 확신할 수 없다. 만약 같이 있는 선교사의 수보다 식인종의 수가 많지 않으면, 식인종은 선교사를 해칠 수 없다. 2인승 배를 사용하여 건너려 할 때, 3명의 선교사와 3명의 식인종 모두 무사히 강 반대편에 도착할 수 있는 방법은 무엇인가?
본문내용
[프로그램]
(defun move_operator (s)
(prog ( L nbr (b (car s)) (mu (car (second s)))
(cu (second (second s)))
(md (car (third s)))
(cd (second (third s ))) )
(cond ((eq b 0)
(setq nbr (cons 1 (cons (list (1- mu) cu) (cons (list (1+ md) cd) nil))))
(if (and (is_ok nbr) (no_killing nbr)) (setq L (cons nbr L)))
(setq nbr (cons 1 (cons (list (- mu 2) cu) (cons (list (+ md 2) cd) nil))))
(if (and (is_ok nbr) (no_killing nbr)) (setq L (cons nbr L)))
(setq nbr (cons 1 (cons (list mu (1- cu)) (cons (list md (1+ cd)) nil))))
(if (and (is_ok nbr) (no_killing nbr)) (setq L (cons nbr L)))
(setq nbr (cons 1 (cons (list mu (- cu 2)) (cons (list md (+ cd 2)) nil))))
(if (and (is_ok nbr) (no_killing nbr)) (setq L (cons nbr L)))
(setq nbr (cons 1 (cons (list (1- mu) (1- cu)) (cons (list (1+ md) (1+ cd)) nil))))
(if (and (is_ok nbr) (no_killing nbr)) (setq L (cons nbr L))) )
참고 자료
없음