Advertisement
GWibisono

algol apa ini?

Feb 5th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. <?php
  2. $num= isset($_GET['i'])?$_GET['i']:2;
  3. $result=array();
  4. $raw=algol($num,$result);
  5. echo '<pre>'.print_r($result,1).print_r($raw,1);
  6.  
  7. function algol($num,&$result){
  8.     $q=array();
  9.     $ar=array();
  10.     $result[]="memory:".memory_get_peak_usage();
  11.     echo "<hr>$num";
  12.     if($num==1){
  13.         $format="%s";
  14.         $result[]="q=";
  15.         $qx="x";
  16.     }
  17.     else{
  18.         $raw=algol($num-1, $result);
  19.         //print_r($raw);
  20.         $qx="x".implode(",x",$raw);
  21.         $result[]="q=".implode(", ",$raw);
  22.     }
  23.    
  24.     $result[]="num:$num";
  25.     $result[]="q(x):$qx";
  26.    
  27.     if($num==1){    
  28.         $q0=sprintf($format,0);
  29.         $result[]="q(0):$q0";
  30.         $ar[]=$q0;
  31.     }
  32.     else{
  33.         $str="";
  34.         foreach($raw as $v){
  35.             $str.=$ar[]="0".$v;
  36.             $str.=",";
  37.         }
  38.         $result[]="q(0):$str";
  39.     }
  40.    
  41.     if($num==1){
  42.         $q1=sprintf($format,1);
  43.         $result[]="q(1):$q1";
  44.         $ar[]=$q1;
  45.     }
  46.     else{
  47.         $str="";
  48.         foreach($raw as $v){
  49.             $str.=$ar[]="1".$v;
  50.             $str.=",";
  51.         }
  52.         $result[]="q(1):$str";
  53.     }
  54.     $result[]="q=".implode(",",$ar);
  55.     return $ar;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement