function CantorExpand($n, $x) { //參數說明 // $n - 排列的位數 // $x - 第幾個 (必須要是字串) //1. $x 先減1 $x = gmp_sub($x, "1"); $str = ""; for ($i = 1; $i <= $n; $i++) { //2. 先算($n-$i)階乘 $fac = gmp_strval(gmp_fact($n - $i)); //3. 再算 $x / ($n-$i) 的商跟餘數 $res = gmp_div_qr($x, $fac); $quotient = gmp_strval($res[0]); $remainder = gmp_strval($res[1]); //4. 比這個位數小的數目總共有 $quotient 個,所以開始找出這個位數 $str .= findMax($quotient); //5. 把餘數設為 $x,下次要使用 $x = $remainder; } return $str; }
<!-- /.container --> </nav> <!-- Header Carousel --> <header id="myCarousel" class="carousel slide"> <!-- Indicators --> <ol class="carousel-indicators"> <li data-target="#myCarousel" data-slide-to="0" class="active"></li> <li data-target="#myCarousel" data-slide-to="1"></li> <li data-target="#myCarousel" data-slide-to="2"></li> </ol> <!-- Wrapper for slides --> <div class="carousel-inner"> <?php $max = findMax($posts->result_array()); foreach ($posts->result_array() as $post) { if ($post['id_posting'] == $max) { ?> <div class="item active"> <div class="fill" style="background-image:url('<?php echo base_url($post['path_gambar']); ?> ');"></div> <div class="carousel-caption"> <h2><?php echo $post['judul']; ?> </h2> </div> </div>
$title = $_GET['title']; $data = $_GET['data']; if (isset($_GET['submitted'])) { echo "<fieldset class=results>"; ?> <legend>Results</legend><?php $temparray = explode(' ', ' ', $data); $temparray = explode(",", $data); sort($temparray); $sum = 0; foreach ($temparray as $value) { $sum = $sum + $value; } $size = sizeof($temparray); $average = $sum / $size; $maxValue = findMax($temparray); echo "<br/><br/><br/>\n\t\t\tThe average for {$title} is " . number_format($average, 1) . "<br/>"; echo "The minimum for {$title} is {$temparray['0']} <br/>"; echo "The maximum for {$title} is {$maxValue} <br/>"; ?> <table> <tr> <th> <?php echo "{$title}"; ?> </th> </tr>
/** * delete * * @param mixed $obj */ function delete(&$node, $obj) { if (!isset($node)) { die; } $diff = compare($node['root'], $obj); echo $diff; if ($diff == 0) { if (isset($node['left'])) { $max = findMax($node['left']); $node['root'] = $max; delete($node['left'], $max); } elseif (isset($node['right'])) { $min = findMin($node['right']); $node['root'] = $min; delete($node['right'], $min); } else { unset($node); } } else { if ($diff < 0) { delete($node['left'], $obj); } else { delete($node['right'], $obj); } } }