function queens_under_attack($board) { global $attacked; // for display outside of this function if (!is_array($board)) { return 'ERROR'; } if (sizeof($board) <= 1) { return '0'; // 1 or 0 pieces? no worry } $boardx = $board; // 2nd compare array $attacked = array(); while (list($position, ) = each($board)) { if (in_array($position, $attacked)) { continue; // already found attack } reset($boardx); while (list($xposition, ) = each($boardx)) { if (in_array($xposition, $attacked)) { continue; // already found attack } if ($xposition == $position) { continue; // ignore self } $col = $position[0]; $row = $position[1]; $xcol = $xposition[0]; $xrow = $xposition[1]; if ($col == $xcol || $row == $xrow) { // check attacks on rows and columns $attacked[] = $position; $attacked[] = $xposition; $attacked = array_unique($attacked); continue; } if (abs(alpha2num($col) - alpha2num($xcol)) == abs($row - $xrow)) { // check diagonals $attacked[] = $position; $attacked[] = $xposition; $attacked = array_unique($attacked); continue; } } } return sizeof($attacked); }
/** * Take the generator string specification produced by parseGeneratorString and * return a list of strings where the patterns are instantiated. * * @param array $patSpecs * @param int $count * @return array */ function generatePatterns($patSpecs, $count) { $patternList = array(); for ($i = 0; $i < $count; $i++) { $str = ''; foreach ($patSpecs as $pat) { if ($pat) { if ($pat[0] == 'String') { $str .= $pat[1][0]; } elseif ($pat[0] == 'Pattern') { if ($pat[1][0] == 'numeric') { $str .= (int) ($pat[1][1] + $i * $pat[1][2]); } elseif ($pat[1][0] == 'alpha') { $charIntVal = ord($pat[1][1]); if ($charIntVal >= 65 and $charIntVal <= 90) { $offset = 0x40; $charIntVal = alpha2num($pat[1][1]); } else { $offset = 0x60; $charIntVal = alpha2num($pat[1][1], $offset); } $str .= num2alpha($charIntVal + $i * $pat[1][2], $offset); } } } } $patternList[] = $str; } return $patternList; }
date_default_timezone_set('Europe/Berlin'); #php.ini => date.timezone = "Europe/Whatever" Rem($ndate, UcFirst(strftime("%A %d %B %Y %T")), date("Y m d H:i:s")); #pat(PHP_OS,,strftime("%A %d %B %Y %T")); #Vendredi 27 Septembre 2013 16:49:36 $D = array('ndate' => "<a id=ndate>" . $ndate . "</a>", 'deblockurl' => '!*%$%M', 'vit' => LOGS . 'Vitale.db', 'starter' => $starter, 'logs' => $a['logs'], 'tmp' => $a['tmp'], 'rt' => $a['rt']); foreach ($D as $k => $v) { redef($k, $v, 1); } e(RU . H . U . $a['args']); #note surl is obselete $D = array('bots' => isbot(), 'mu' => mu(H . U), 'u2' => Preg_Replace("~(\\?|&).*~", '', U), 'ipf' => IPSTORE . IP . ".db", 'fkeyword' => TMP . 'keyw/' . IP, 'u3' => BadQ(U)); foreach ($D as $k => $v) { redef($k, $v, 1); } $D = array('hu3' => H . '/' . U3, 'hu4' => '//' . H . '/' . U3, 'seed' => alpha2num(u2), 'su2' => SR . U2, 'CACHEPATH' => TMP . 'cache/' . MU . '.ca'); /**/ foreach ($D as $k => $v) { redef($k, $v, 1); } #$_ENV $_ENV['c']['cachetime'] = 3600 * 100; #100h par seconde de calcul-1h pour 10ms $D = array('lasttime' => 0, 'lastmemusage' => 0, 'lastkey' => 0, 'maxop' => 4000, 'mu' => MU, 'script' => $a['SCRIPT_FILENAME'], 'Mem' => array(), 'dbt' => array(), 'yt' => array('host' => RH, 'ip' => IP, 'dlp' => SU, 'u' => SU, 'r' => REFE, 'ref' => REFE)); foreach ($D as $k => $v) { $_ENV[$k] = $v; } $pi = pathinfo(SU); $pi['extension'] = extension(SU); #pour la suite, extensions mauvaises etc.. #identification utilisateurs ou serveurs de prod;||in_Array(ip,array('46.14.5.130')