I am trying to implement a program to solve the cannibals and missionaries
problem. Have someone already done this program ?? If yes, could you send me
for analysing ???
"Andr� Ormastroni" <·····@centroin.com.br> writes:
> I am trying to implement a program to solve the cannibals and
> missionaries problem. Have someone already done this program ??
Someone did this program on an electronic computer in the
1950s. Possibly even earlier.
> If yes, could you send me for analysing ???
Here's a version from 1976 in Motorola assembler for your "analysis".
http://ftp.unina.it/pub/electronics/motorola/usergroup/ug052
Christopher
"Andr� Ormastroni" <·····@centroin.com.br> writes:
>
> I am trying to implement a program to solve the cannibals and
> missionaries problem. Have someone already done this program ?? If
> yes, could you send me for analysing ???
;; Here's a solution in a declarative formalism:
(defun print-solution (solution &optional (stream t))
(format stream "~{~A~%~}" solution))
(defparameter *cannibals-solution*
'("Start"
"1 Cannibal and 1 Missionary cross river"
"1 Missionary returns"
"2 Cannibals cross river"
"1 Cannibal returns"
"2 Missionaries cross river"
"1 Cannibal and 1 Missionary return (!)"
"2 Missionaries cross river"
"1 Cannibal returns"
"2 Cannibals cross river"
"1 Cannibal returns"
"2 Cannibals cross river"
"Done"))
(print-solution *cannibals-solution*)
;; An iterative version would look like:
(defun print-solution-iterative (solution &optional (stream t))
(dolist (phrase solution)
(format stream "~A~%" phrase)))
;; An iterative version using loop would look like:
(defun print-solution-loop (solution &optional (stream t))
(loop for phrase in solution
do (format stream "~A~%" phrase)))
;; A mapping solution would look like:
(defun print-solution-mapping (solution &optional (stream t))
(mapc #'(lambda (phrase) (format stream "~A~%" phrase)) solution)
nil)
--
Thomas A. Russ, USC/Information Sciences Institute ···@isi.edu
Thomas A. Russ schrieb:
> (defparameter *cannibals-solution*
> '("Start"
> "1 Cannibal and 1 Missionary cross river"
> "1 Missionary returns"
At this point, there are 3 missionaries and only 2
cannibals on the first side of the river. This will
allow the missionaries to baptize the cannibals,
which should be avoided :-)
Ralf