function calculate_combinations($numbers, $target) { $woot = 0; foreach (make_comb($numbers) as $comb) { if (array_sum($comb) == $target) { if (DEBUG) { echo PHP_EOL . 'DEBUG : ' . json_encode($comb) . PHP_EOL; } $woot++; } } return $woot; }
ini_set('memory_limit', '512M'); //функции автозагрузки классов function convert_class_to_filename($class) { return './classes/class_' . str_replace('_', '/', $class) . '.php'; } function __autoload($class) { @(include_once convert_class_to_filename($class)); } function timeMeasure() { list($msec, $sec) = explode(chr(32), microtime()); return $sec + $msec; } include_once '../db_connect.php'; //подключаемся к базе $dbh = mysql_connect(host, user, pswd) or die("Не могу соединиться с MySQL."); mysql_select_db(SCAD) or die("Не могу подключиться к базе."); mysql_query("SET NAMES utf8"); mysql_query("TRUNCATE TABLE " . combinations); $fac_factors = array(1.0, 0.9, 0.95, 0.95, 0.95, 0.95, 0.95, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.0, 0.0, 0.0, 0.0, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9); $unfac_factors = array(0.91, 0.75, 0.86, 0.86, 0.86, 0.86, 0.86, 0.82, 0.82, 0.82, 0.82, 0.5600000000000001, 0.5600000000000001, 0.0, 0.0, 0.0, 0.0, 0.45, 0.45, 0.65, 0.65, 0.65, 0.65); $comb_number = 1; make_comb(&$comb_number, $fac_factors); //FACTORED make_comb(&$comb_number, $unfac_factors); //UNFACTORED echo $comb_number - 1 . ' combinations were created.<br/>'; //закрываем соединение с базой mysql_close($dbh);