代码范例收集

// 数字1-9, 找出9位数,使得其从左边开始,每第n(1<=n<=9)位组成的数字都能被n整除
class Cat {
	public $result = [];
	
	public function c($ss, array $aa, $count) {


		foreach($aa as $a){
			$tmp = $ss.$a;
			
			if(((int)$tmp % $count) === 0){
				$bb = array_diff($aa,[$a]);

				$this->c($tmp,$bb,$count+1);
			}
		}
		if(empty($aa)){
			$this->result[] = $ss;
		}

		return $this;
	}

	public function getResult() {
		return $this->result;
	}
}


$cat = (new Cat())->c('', ['1','2','3','4','5','6','7','8','9'], 1)->getResult();
print_r($cat);