Exemple #1
0
function shut_down()
{
    if (!isset($_POST['comb']) || $_POST['comb'] != "prevent") {
        comb("shut_down", $_SERVER['SCRIPT_FILENAME']);
        unset($_POST["comb"]);
    }
}
Exemple #2
0
function comb($arr, $len = 0, $str = "")
{
    global $combres;
    $arr_len = count($arr);
    if ($len == 0) {
        $combres[] = $str;
    } else {
        for ($i = 0; $i < $arr_len - $len + 1; $i++) {
            $tmp = array_shift($arr);
            if (!empty($str)) {
                $aa = $str . "," . $tmp;
            } else {
                $aa = $tmp;
            }
            comb($arr, $len - 1, $aa);
        }
    }
}
Exemple #3
0
 function index()
 {
     $this->load->model("comm_model", "comm");
     $content = file_get_contents("./csv/Ac Motors.csv");
     $content = str_replace(array("\r\n", "\r"), "\n", $content);
     $arrcontent = explode("\n", $content);
     foreach ($arrcontent as $k => $v) {
         $attrs = explode(",", $v);
         if ($k == 0) {
             $catname = $attrs[0];
         } else {
             foreach ($attrs as $j => $a) {
                 if (empty($a)) {
                     continue;
                 }
                 if ($j == 0) {
                     $mattrs[$catname][$attrs[0]] = array();
                 } else {
                     $mattrs[$catname][$attrs[0]][] = $a;
                 }
             }
         }
     }
     dump($mattrs);
     die;
     foreach ($mattrs as $k => $m) {
         $catname = $k;
         dump($catname);
         $findcat = $this->comm->find("category", array("catname" => $catname));
         $catid = $findcat['catid'];
         dump($findcat);
         if (!$findcat) {
             dump("catname is not exist");
             die;
         } else {
             if ($findcat['parentid'] != 0) {
                 dump("catname is not parent");
                 die;
             }
         }
         $i = 0;
         foreach ($m as $option => $value) {
             $findoption = $this->comm->find("category_option", array("catid" => $findcat['catid'], "name" => $option));
             if ($findoption) {
                 $oid = $findoption['oid'];
             } else {
                 $oid = $this->comm->create("category_option", array("catid" => $findcat['catid'], "name" => $option));
             }
             foreach ($value as $v) {
                 $findov = $this->comm->find("category_option_value", array("oid" => $oid, "value" => $v));
                 if (!$findov) {
                     $this->comm->create("category_option_value", array("oid" => $oid, "value" => $v));
                 } else {
                     dump($option . " exsit");
                 }
             }
             if ($i < 3) {
                 $this->comm->update("category_option", array("catid" => $findcat['catid'], "oid" => $oid), array("required" => 1, "listorder" => $i));
             } else {
                 $this->comm->update("category_option", array("catid" => $findcat['catid'], "oid" => $oid), array("required" => 2, "listorder" => $i));
             }
             $i++;
         }
     }
     /*
     foreach($mattrs as $k => $m){
     	$catname = $k;
     	dump($catname);
     	$findcat = $this->comm->find("category",array("catname"=>$catname));
     	dump($findcat);
     	if(!$findcat){
     		dump("catname is not exist");
     		die();
     	}else{
     		if($findcat['parentid']!=0){
     			dump("catname is not parent");
     			die();
     		}
     		
     	}
     	
     	
     	
     	foreach($m as $option => $value){
     		$findoption = $this->comm->find("category_option",array("catid"=>$findcat['catid'],"name"=>$option));
     		//dump($findoption);
     		if($findoption){
     			$findov = $this->comm->find("category_option_value",array("oid"=>$findoption['oid'],"value"=>$option));
     			if(!$findov){
     				$this->comm->create("category_option_value",array("oid"=>$findoption['oid'],"value"=>$option));
     			}else{
     				dump($option." exsit");
     			}
     		}
     		
     		
     		$findoption = $this->comm->find("category_option",array("catid"=>$findcat['catid'],"name"=>$option));
     		dump($findoption);
     		
     		if(!$findoption){
     			dump("Create");
     			die();
     			//$this->comm->create("category_option")
     		}else{
     			if($findoption['required'] and !empty($findoption['value'])){
     				dump("already option added");
     				die();
     			}else{
     				dump("update");
     				
     				$values = implode("||",$value);
     				$this->comm->update("category_option",array("catid"=>$findcat['catid'],"oid"=>$findoption['oid']),array("required"=>1,"value"=>$values));
     			}
     		}
     		
     	}
     		
     }
     */
     $option = array();
     foreach ($mattrs[$catname] as $k => $m) {
         if (count($option) < 3) {
             $option[] = $k;
         }
     }
     $this->load->helper("comb");
     global $combres;
     comb($option, 1);
     $one = $combres;
     comb($option, 2);
     comb($option, 3);
     //dump($combres);
     dump($one);
     $all = $combres;
     //dump($all);
     foreach ($one as $k => $v) {
         //$v = str_replace(",","",$v);
         foreach ($mattrs[$catname][$v] as $value) {
             $match_one[] = $value;
             $find = $this->comm->find("attrtag", array("tag" => $value, "catid" => $catid));
             if (!$find) {
                 $op = $this->comm->find("category_option", array("catid" => $catid, "name" => $v));
                 $ov = $this->comm->find("category_option_value", array("value" => $value, "oid" => $op['oid']));
                 $linkurl = $ov['oid'] . "-" . $ov['id'];
                 $this->comm->create("attrtag", array("tag" => $value, "catid" => $catid, "linkurl" => $linkurl));
             }
         }
         unset($all[$k]);
     }
     dump($match_one);
     dump("===========================取一个" . count($match_one) . "=======================");
     dump($all);
     $total = 0;
     foreach ($all as $k => $v) {
         $match_all = array();
         //$v = substr($v,1);
         $option = explode(",", $v);
         //dump($option);
         foreach ($option as $o) {
             $match_all[] = $mattrs[$catname][$o];
             //$array[] = $mattrs[$catname][$o];
         }
         $result = combination($match_all);
         $total += count($result);
         foreach ($result as $res) {
             $linkurl = array();
             $tag = array();
             foreach ($res as $j => $r) {
                 $op = $this->comm->find("category_option", array("catid" => $catid, "name" => $option[$j]));
                 $ov = $this->comm->find("category_option_value", array("value" => $r, "oid" => $op['oid']));
                 $linkurl[] = $ov['oid'] . "-" . $ov['id'];
                 $tag[] = $r;
             }
             $linkurl = implode("_", $linkurl);
             $tag = implode(" ", $tag);
             $find = $this->comm->find("attrtag", array("tag" => $tag, "catid" => $catid));
             if (!$find) {
                 $this->comm->create("attrtag", array("tag" => $tag, "catid" => $catid, "linkurl" => $linkurl));
             }
         }
     }
     dump($total);
 }
Exemple #4
0
    return factorial($n) / factorial($k) / factorial($n - $k);
}
function row($k)
{
    ?>
      <div class="row">
        <?php 
    for ($i = 0; $i <= $k; $i++) {
        print combo($k, $i) . " ";
    }
    ?>
      </div>
      <?php 
}
?>
      <h1>Pascal's Triangle</h1>
      <?php 
for ($k = 0; $k < 13; $k++) {
    row($k);
}
?>
	<p> <?php 
row(6, 3);
?>
 </p>
  <p> <?php 
echo comb(8, 4);
?>
 </p>
  </body>
</html>
Exemple #5
0
 function index()
 {
     ini_set('max_execution_time', 0);
     ini_set('memory_limit', '14048M');
     $this->load->model("comm_model", "comm");
     $catid = $this->uri->rsegment(3, 0);
     $mattrs = array();
     $category = $this->comm->find("category", array("catid" => $catid));
     if (!$category) {
         dump($catid);
         die;
     }
     if ($category['collect']) {
         dump("already make");
         die;
     }
     $catid = $category['catid'];
     $catname = $category['catname'];
     $options = $this->comm->findAll("category_option", array("catid" => $catid, "required" => 1), "listorder asc");
     if (!$options) {
         dump($catid);
         //$this->comm->update("category",array("catid"=>$catid),array("collect"=>1));
         //$redirect_cat = $this->comm->find("category","parentid=0 and collect=0","catid asc");
         //dump($redirect_cat);
         //echo "<script>location.href='/process/readattrs/index/".$redirect_cat['catid']."'</script>";
         die("not attrs");
     }
     foreach ($options as $op) {
         $ov = $this->comm->findAll("category_option_value", array("oid" => $op['oid']));
         foreach ($ov as $v) {
             $mattrs[$category['catname']][$op['name']][] = $v['value'];
         }
     }
     dump($mattrs);
     $option = array();
     foreach ($mattrs[$catname] as $k => $m) {
         //if(count($option)<3){
         $option[] = $k;
         //}
     }
     $this->load->helper("comb");
     global $combres;
     if (count($option) > 4) {
         $combnum = 4;
     } else {
         $combnum = count($option);
     }
     for ($i = 1; $i <= $combnum; $i++) {
         comb($option, $i);
         if ($i == 1) {
             $one = $combres;
         }
     }
     //dump($combres);
     //dump($one);
     $all = $combres;
     //dump($all);
     //die();
     foreach ($one as $k => $v) {
         //$v = str_replace(",","",$v);
         foreach ($mattrs[$catname][$v] as $value) {
             $match_one[] = $value;
             $find = $this->comm->find("attrtag", array("tag" => $value, "catid" => $catid));
             if (!$find) {
                 $op = $this->comm->find("category_option", array("catid" => $catid, "name" => $v));
                 $ov = $this->comm->find("category_option_value", array("value" => $value, "oid" => $op['oid']));
                 $linkurl = $ov['oid'] . "-" . $ov['id'];
                 $attrs = $ov['oid'] . "|" . $ov['id'];
                 $this->comm->create("attrtag", array("tag" => $value, "catid" => $catid, "catname" => $catname, "attrs" => $attrs, "linkurl" => $linkurl, "num" => 1));
             }
         }
         unset($all[$k]);
     }
     dump($match_one);
     dump("===========================取一个" . count($match_one) . "=======================");
     //dump($all);
     $total = 0;
     foreach ($all as $k => $v) {
         $match_all = array();
         //$v = substr($v,1);
         $option = explode(",", $v);
         //dump($option);
         foreach ($option as $o) {
             $match_all[] = $mattrs[$catname][$o];
             //$array[] = $mattrs[$catname][$o];
         }
         $result = combination($match_all);
         $total += count($result);
         foreach ($result as $res) {
             $linkurl = array();
             $attrs = array();
             $tag = array();
             foreach ($res as $j => $r) {
                 $op = $this->comm->find("category_option", array("catid" => $catid, "name" => $option[$j]));
                 $ov = $this->comm->find("category_option_value", array("value" => $r, "oid" => $op['oid']));
                 $linkurl[] = $ov['oid'] . "-" . $ov['id'];
                 $attrs[] = $ov['oid'] . "|" . $ov['id'];
                 $tag[] = $r;
             }
             $num = count($attrs);
             $linkurl = implode("_", $linkurl);
             $attrs = implode(",", $attrs);
             $tag = implode(" ", $tag);
             $this->db->query("lock tables wl_attrtag write");
             $find = $this->comm->find("attrtag", array("tag" => $tag, "catid" => $catid));
             if (!$find) {
                 $this->comm->create("attrtag", array("tag" => $tag, "catid" => $catid, "catname" => $catname, "attrs" => $attrs, "linkurl" => $linkurl, "num" => $num));
             }
             $this->db->query("unlock tables");
         }
         //释放内存
         unset($result);
     }
     dump($total);
     $this->comm->update("category", array("catid" => $catid), array("collect" => 1));
     //$redirect_cat = $this->comm->find("category","parentid=207 and collect=0","listorder ASC");
     //dump($redirect_cat);
     //echo "<script>location.href='/process/readattrs/index/".$redirect_cat['catid']."'</script>";
 }