~php <? $s = new survive(); $s->to_right(); class survive { var $left, $right; function __construct() { $this->left = array("canni" => 3, "missi" => 3); $this->right = array("canni" => 0, "missi" => 0); } function to_right() { if($this->left[canni]==$this->left[missi]&&$this->left[canni]==3) $this->ferry(1,1); elseif($this->left[canni]<>$this->left[missi]&&$this->left[canni]>1) $this->ferry(2,0); else $this->ferry(0,2); $this->to_left(); } function to_left() { if($this->right[canni]==$this->right[missi]&&$this->right[canni]==2) $this->ferry(-1,-1); elseif($this->right[canni]==$this->right[missi]) $this->ferry(0,-1); else $this->ferry(-1,0); $this->to_right(); } function ferry($canni, $missi) { if($canni>=0&&$missi>=0) echo "우측 식인종 {$this->right[canni]}+$canni, 선교사 {$this->right[missi]}+$missi<br>"; elseif($canni<=0&&$missi<=0) echo "좌측 식인종 {$this->left[canni]}+".(-$canni).", 선교사 {$this->left[missi]}+".(-$missi)."<br>"; else die("에러: $canni, $missi"); $this->left[canni] -= $canni; $this->left[missi] -= $missi; $this->right[canni] += $canni; $this->right[missi] += $missi; if(!$this->left[canni]&&!$this->left[missi]) exit(); } } ?>