function itemuse(&$theitem) { if (eval(__MAGIC__)) { return $___RET_VALUE; } eval(import_module('sys', 'player', 'itemmain', 'logger')); $itm =& $theitem['itm']; $itmk =& $theitem['itmk']; $itme =& $theitem['itme']; $itms =& $theitem['itms']; $itmsk =& $theitem['itmsk']; if (strpos($itmk, 'A') === 0) { $eqp = 'art'; $noeqp = ''; if ($noeqp && strpos(${$eqp . 'k'}, $noeqp) === 0 || !${$eqp . 's'}) { ${$eqp} = $itm; ${$eqp . 'k'} = $itmk; ${$eqp . 'e'} = $itme; ${$eqp . 's'} = $itms; ${$eqp . 'sk'} = $itmsk; $log .= "装备了<span class=\"yellow\">{$itm}</span>。<br>"; $itm = $itmk = $itmsk = ''; $itme = $itms = 0; } else { swap(${$eqp}, $itm); swap(${$eqp . 'k'}, $itmk); swap(${$eqp . 'e'}, $itme); swap(${$eqp . 's'}, $itms); swap(${$eqp . 'sk'}, $itmsk); $log .= "卸下了<span class=\"red\">{$itm}</span>,装备了<span class=\"yellow\">{${$eqp}}</span>。<br>"; } return; } $chprocess($theitem); }
function selection_sort($arr) { $last = count($arr) - 1; $time_start = microtime(true); for ($i = 0; $i < count($arr) - $i; $i++) { $min_idx = $i; $max_idx = $last - $i; for ($j = $i; $j < count($arr) - $i; $j++) { if ($arr[$min_idx] > $arr[$j]) { $min_idx = $j; } if ($arr[$max_idx] < $arr[$j]) { $max_idx = $j; } } swap($i, $min_idx, $arr); // swap the minimun to the head of the array; if ($i == $max_idx) { $max_idx = $min_idx; } swap($last - $i, $max_idx, $arr); // swap the maximum to the end of the array; } $time_end = microtime(true); $time = $time_end - $time_start; echo "<font color='red'>The sort took: " . $time . " second(s).</font><br>"; echo "<b>Sorted Array: <br></b>"; var_dump($arr); }
function insertion_sort($arr) { //Base case $first = $arr[0]; $second = $arr[1]; if ($arr[1] < $arr[0]) { swap($first, $second); $arr[0] = $first; $arr[1] = $second; } //Induction Hypothesis add 2 foreach ($arr as $keys => $values) { //keys + 2 is current key for ($i = $keys + 2; $i < count($arr); $i++) { for ($j = $keys + 2; $j == 0; $j--) { if ($arr[$keys + 2] < $arr[$j]) { // swap variables // swap($arr[$j],$arr[$keys+2]); $temp = $arr[$j]; $arr[$j] = $arr[$keys + 2]; $arr[$keys + 2] = $temp; } } } } var_dump($arr); }
function swap3($s, $rr) { $s = explode("\\\\", $s); foreach ($rr as $r) { $s = array_map(function ($s) use($r) { return swap($s, "\\{$r}", $r); }, $s); } return implode("\\\\", $s); }
public function test_prune_doesnt_execute_if_configuration_directory_doesnt_exist() { $files = Mockery::mock(Filesystem::class . '[exists]'); swap(Filesystem::class, $files); $files->shouldReceive('exists')->with(VALET_HOME_PATH . '/config.json')->andReturn(false); $config = Mockery::mock(Configuration::class . '[read,write]', [$files]); $config->shouldReceive('read')->never(); $config->shouldReceive('write')->never(); $config->prune(); }
public function test_caddy_daemon_is_placed_in_correct_location() { $files = Mockery::mock(Filesystem::class . '[put]'); swap(Filesystem::class, $files); $caddy = resolve(Caddy::class); $files->shouldReceive('put')->andReturnUsing(function ($path, $contents) use($caddy) { $this->assertEquals($caddy->daemonPath, $path); $this->assertTrue(strpos($contents, VALET_HOME_PATH) !== false); }); $caddy->installCaddyDaemon(); }
function minHeapFixup(array &$a, $i) { for ($j = (int) (($i - 1) / 2); $j >= 0 && $i != 0 && $a[$i] < $a[$j]; $i = $j, $j = (int) (($i - 1) / 2)) { swap($a[$i], $a[$j]); } /*$j = (int)(($i-1)/2); while ( $j>=0 && $i!=0 && $a[$i]<$a[$j] ) { swap($a[$i], $a[$j]); $i=$j; $j=(int)(($i-1)/2); }*/ }
function selectSort(&$arr) { $len = count($arr); for ($i = 0; $i < $len; $i++) { $pos = selectMin($arr, $i, $len); if ($i != $pos) { // 找到的最小数不是第一个数时,交换这两个数 swap($arr[$i], $arr[$pos]); } } }
function partition(&$array, $left, $right) { $k = $left - 1; $pivot = $array[$right]; for ($i = $left; $i <= $right; $i++) { if ($array[$i] <= $pivot) { $k += 1; swap($array, $k, $i); } } return $k; }
function cook65($b65, $fm, $to) { $pos = $fm + $to; if ($pos < 0 || $pos > 64 || $fm == $pos) { return $b65; } if ($fm > $pos) { @swap($fm, $pos); } $b65 = @substr($b65, 0, $fm) . @substr($b65, $pos, 1) . @substr($b65, $fm + 1, $pos - $fm - 1) . @substr($b65, $fm, 1) . @substr($b65, $pos + 1); return @substr($b65, $pos) . @substr($b65, 0, $pos); }
function permutation($str, $i, $n) { if ($i == $n) { print $str . "<br />"; } else { for ($j = $i; $j < $n; $j++) { $str = swap($str, $i, $j); permutation($str, $i + 1, $n); $str = swap($str, $i, $j); } } }
function bubbleSort(&$array) { do { $swapped = false; for ($i = 0, $c = count($array) - 1; $i < $c; $i++) { if ($array[$i] > $array[$i + 1]) { swap($array, $i); $swapped = true; } } } while ($swapped); }
/** * Returns the Permutations of a String */ function permute($in, $startPos, $endPos) { if (strlen($in) == 1 || $startPos == $endPos) { print $in . "\n"; return $in; } else { for ($a = $startPos; $a < $endPos; $a++) { $in = swap($in, $startPos, $a); permute($in, $startPos + 1, $endPos); } } }
public function test_symlink_creates_symlink_to_given_path() { $files = Mockery::mock(Filesystem::class); $files->shouldReceive('ensureDirExists')->once()->with(VALET_HOME_PATH . '/Sites', user()); $config = Mockery::mock(Configuration::class); $config->shouldReceive('prependPath')->once()->with(VALET_HOME_PATH . '/Sites'); $files->shouldReceive('symlinkAsUser')->once()->with('target', VALET_HOME_PATH . '/Sites/link'); swap(Filesystem::class, $files); swap(Configuration::class, $config); $linkPath = resolve(Site::class)->link('target', 'link'); $this->assertEquals(VALET_HOME_PATH . '/Sites/link', $linkPath); }
function getclub($who, &$c1, &$c2, &$c3) { global $db, $tablepre, $starttime, $validtime; $result = $db->query("SELECT gid FROM {$tablepre}winners ORDER BY gid desc LIMIT 1"); $t = $db->fetch_array($result); $curgid = $t['gid'] + 1; $result = $db->query("SELECT uid FROM {$tablepre}users WHERE username='******'"); $t = $db->fetch_array($result); $curuid = $t['uid'] + 2; $result = $db->query("SELECT pid FROM {$tablepre}players WHERE name='{$who}' AND type=0"); $t = $db->fetch_array($result); $curpid = $result['pid'] + 3; $c1 = calc(12347, 10007, $curgid, $curuid, $curpid, $starttime, $validtime); $c1 %= 6; if ($c1 == 0) { $c1 = 9; } //超能称号为9号 $delt = 0; while ($delt <= 30) { $c2 = calc(10009, 7789 + $delt, $curgid, $curuid, $curpid, $starttime, $validtime); $c2 %= 5; $c2++; //第二个称号不允许超能 if ($c1 != $c2) { break; } $delt++; } if ($delt > 30) { if ($c1 == 1) { $c2 = 2; } else { $c2 = 1; } } $c3 = calc(11131, 6397, $curgid, $curuid, $curpid, $starttime, $validtime); $clubid = array(6, 7, 8, 99, 10, 11, 13, 14, 16, 18, 19, 7, 99, 13, 14, 18, 6, 19, 13, 14, 18); $c3 %= 21; $c3 = $clubid[$c3]; if ($c1 == $c3 || $c2 == $c3) { $c3 = 99; } if ($c1 > $c2) { swap($c1, $c2); } if ($c1 > $c3) { swap($c1, $c3); } if ($c2 > $c3) { swap($c2, $c3); } }
function permute($str, $i, $n) { if ($i == $n) { print "{$str}\n"; } else { for ($j = $i; $j < $n; $j++) { swap($str, $i, $j); permute($str, $i + 1, $n); swap($str, $i, $j); // backtrack. } } }
function partition($arr, $left, $right, $pivot) { $pivValue = $arr[$pivot]; swap($arr, $pivot, $right); $storePos = $left; for ($i = $left; $i < $right; $i++) { if ($arr[$i] < $pivValue) { swap($arr, $i, $storePos); $storePos++; } } swap($list, $storePos, $right); return $storePos; }
function quicksort(&$arr, $st, $end) { if ($st == $end) { return; } $sep = $st; for ($i = $st + 1; $i < $end; $i++) { if ($arr[$i] < $arr[$st]) { swap($arr, ++$sep, $i); } } swap($arr, $st, $sep); quicksort($arr, $st, $sep); quicksort($arr, $sep + 1, $end); }
function partition(array &$arr, $pivotIndex, $startIndex = 0, $stopIndex = null) { $stopIndex = $stopIndex !== null ? $stopIndex : count($arr) - 1; swap($arr[$startIndex], $arr[$pivotIndex]); $pivot = $arr[$startIndex]; $i = $startIndex + 1; for ($j = $startIndex; $j <= $stopIndex && $i <= $stopIndex; $j++) { if ((double) $arr[$j] < (double) $pivot) { swap($arr[$j], $arr[$i]); $i++; } } swap($arr[$startIndex], $arr[$i - 1]); return $i - 1; }
function partition(&$A, $p, $r) { $pviot = $A[$r]; $j = $p; $i = $p - 1; while ($j < $r) { if ($A[$j] < $pviot) { $i++; swap($A[$i], $A[$j]); } $j++; } $i = $i + 1; swap($A[$i], $A[$r]); return $i; }
function bubble_sort($arr) { $time_start = microtime(true); for ($i = 0; $i < count($arr); $i++) { for ($j = 0; $j < count($arr) - $i - 1; $j++) { if ($arr[$j] >= $arr[$j + 1]) { swap($j, $j + 1, $arr); } } } $time_end = microtime(true); $time = $time_end - $time_start; echo "This bubble sort took: " . $time . " second(s).<br>"; echo "The sorted array: <br>"; var_dump($arr); }
public function test_install_installs_and_places_configuration_files_in_proper_locations() { $ubuntu = Mockery::mock(Linux::class); $ubuntu->shouldReceive('ensureInstalled')->once()->with('dnsmasq'); $ubuntu->shouldReceive('restartService')->once()->with('dnsmasq'); swap(Linux::class, $ubuntu); $dnsMasq = resolve(StubForCreatingCustomDnsMasqConfigFiles::class); $dnsMasq->exampleConfigPath = __DIR__ . '/files/dnsmasq.conf'; $dnsMasq->configPath = __DIR__ . '/output/dnsmasq.conf'; $dnsMasq->install('dev'); $this->assertSame('address=/.dev/127.0.0.1' . PHP_EOL, file_get_contents(__DIR__ . '/output/custom-dnsmasq.conf')); $this->assertSame('test-contents conf-file=' . __DIR__ . '/output/custom-dnsmasq.conf ', file_get_contents(__DIR__ . '/output/dnsmasq.conf')); }
function heapSort(&$arr) { // 添加头元素 array_unshift($arr, 0); $len = count($arr) - 1; // 初始化堆 for ($i = floor($len / 2); $i > 0; $i--) { heapAdjust($arr, $i, $len); } for ($i = $len; $i > 0; $i--) { swap($arr[1], $arr[$i]); heapAdjust($arr, 1, $i - 1); } // 删除头元素 array_shift($arr); }
function permute_swap($str, $i, $n) { if ($i == $n - 1) { foreach ($str as $c) { echo $c; } echo "\n"; } else { for ($j = $i; $j < $n; $j++) { // Backtracking swap($str[$i], $str[$j]); permute_swap($str, $i + 1, $n); swap($str[$i], $str[$j]); } } }
function permute($str, $i, $n, &$arr) { //, &$arr) { if (!is_array($arr)) { $arr = array(); } if ($i == $n) { $arr[] = $str; // print "$str\n"; } else { for ($j = $i; $j < $n; $j++) { swap($str, $i, $j); permute($str, $i + 1, $n, $arr); swap($str, $i, $j); } } }
function bubble_sort($arr) { $time_start = microtime(true); $x = count($arr) - 1; while ($x >= 0) { for ($i = 0; $i < count($arr) - 1; $i++) { $i2 = $i + 1; if ($arr[$i] > $arr[$i2]) { $arr = swap($arr, $i, $i2); } } $x--; } $time_stop = microtime(true); echo $time_stop - $time_start; var_dump($arr); }
function partition(array &$array, $start, $end, $pivotIndex, $fieldToCompare) { $pivot = $array[$pivotIndex][$fieldToCompare]; $left = $start; $right = $end; while ($right > $left) { while ($left < $end && $array[$left][$fieldToCompare] <= $pivot) { $left++; } while ($right > $start && $array[$right][$fieldToCompare] > $pivot) { $right--; } if ($right > $left) { swap($array, $left, $right); } } swap($array, $pivotIndex, $right); return $right; }
/** * Get the substring that two strings have in common. * * @param string $str1 * @param string $str2 * @return string */ public static function intersect($str1, $str2) { if ($str1 === $str2) { return $str1; } $str = ''; $str1 = str_split($str1); $str2 = str_split($str2); if (count($str1) > count($str2)) { swap($str1, $str2); } foreach ($str1 as $i => $char) { if ($char !== $str2[$i]) { break; } $str .= $char; } return $str; }
function packDouble($value, $mode = 'LE') { $value = (double) $value; $bin = pack("d", $value); //We test if the conversion of an integer (1) is done as LE or BE by default switch (pack('L', 1)) { case pack('V', 1): //Little Endian $result = $mode == 'LE' ? $bin : swap($bin); break; case pack('N', 1): //Big Endian $result = $mode == 'BE' ? $bin : swap($bin); break; default: //Some other thing, we just return false $result = FALSE; } return $result; }
function bubbleSort($numbers) { $length = sizeOf($numbers); $storage = 0; $previousIndex = 0; $swapped = true; $i = 0; $counter = 0; while ($counter < $length) { for ($i = 1; $i < $length; $i++) { $swapped = false; if ($numbers[$i] < $numbers[$i - 1]) { swap($numbers, $i); $swapped = true; } } $counter++; } return $numbers; }