Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <pre>
- <?php
- //============================
- define('_ANGKA',8);
- //define('_HURUF','abcdef');
- define('_HURUF','abcabcabc');
- //============================
- $p=0;
- $dt[$p]['n']='Heilbert SilenTears Mapaly';
- echo "===\nHeilbert SilenTears Mapaly\n";
- $t1 = MICROTIME(TRUE);
- $angka=_ANGKA;
- $huruf=_HURUF;
- while(strlen($huruf))
- {
- $i=($angka-1) % strlen($huruf);
- echo $huruf[($angka-1) % strlen($huruf)];
- while($i<strlen($huruf))
- {
- if($i==strlen($huruf)-1)
- $huruf=substr($huruf,0,-1);
- else
- $huruf[$i]=$huruf[$i+1];
- $i++;
- }
- }
- $t2 = MICROTIME(TRUE);
- $dt[$p]['t']=$t2-$t1;
- echo "\nMakan waktu: ".$dt[$p]['t']." sekon\n";
- //===
- $p=1;
- $dt[$p]['n']='Heilbert SilenTears Mapaly *';
- echo "===\nHeilbert SilenTears Mapaly *\n";
- $t1 = MICROTIME(TRUE);
- $angka=_ANGKA;
- $huruf=_HURUF;
- while(strlen($huruf))
- {
- $i=($angka-1) % strlen($huruf);
- echo $huruf[$i];
- $b=str_split($huruf);
- array_splice($b,$i,1);
- $huruf=implode('',$b);
- }
- $t2 = MICROTIME(TRUE);
- $dt[$p]['t']=$t2-$t1;
- echo "\nMakan waktu: ".$dt[$p]['t']." sekon\n";
- //===
- $p=2;
- $dt[$p]['n']='Sandy Racy';
- echo "===\nSandi Racy\n";
- $t1 = MICROTIME(TRUE);
- $angka=_ANGKA;
- $huruf=_HURUF;
- while($huruf!='')
- {
- $jumlah=strlen($huruf);
- $j=0;
- for($i=1; $i<=$angka; $i++)
- {
- $hasil[$i]=$huruf[$j];
- $i%$jumlah==0 ? $j=0 : $j++;
- }
- echo $hasil[$angka];
- $huruf=str_replace($hasil[$angka], '', $huruf);
- }
- $t2 = MICROTIME(TRUE);
- $dt[$p]['t']=$t2-$t1;
- echo "\nMakan waktu: ".$dt[$p]['t']." sekon\n";
- //===
- $p=3;
- $dt[$p]['n']='Noer Cholis';
- echo "===\nNoer Cholis\n";
- $t1 = MICROTIME(TRUE);
- $angka=_ANGKA;
- $huruf=_HURUF;
- function recursive($huruf,$angka,$hasil=''){
- if(strlen($huruf)>=1):
- $genhuruf = autohuruf($huruf,$angka);
- $hasil.= $genhuruf[$angka-1];
- $huruf = str_replace($genhuruf[$angka-1],"",$huruf);
- $hasil = recursive($huruf,$angka,$hasil);
- endif;
- return $hasil;
- }
- function autohuruf($huruf,$angka){
- if(strlen($huruf) < $angka):
- $huruf.=$huruf;
- endif;
- if(strlen($huruf) < $angka):
- $huruf.=autohuruf($huruf,$angka);
- endif;
- return $huruf;
- }
- echo recursive($huruf,$angka);
- $t2 = MICROTIME(TRUE);
- $dt[$p]['t']=$t2-$t1;
- echo "\nMakan waktu: ".$dt[$p]['t']." sekon\n";
- //===
- $p=4;
- $dt[$p]['n']='Ahmad Anang Atmahadli';
- echo "===\nAhmad Anang Atmahadli\n";
- $t1 = MICROTIME(TRUE);
- $angka=_ANGKA;
- $huruf=_HURUF;
- while(!empty($huruf)){
- $h=str_split($huruf);
- $n=strlen($huruf);
- $b=floor($angka/$n);
- $s=$angka%$n;
- if($s==0)$s=$n;
- echo $h[$s-1];
- unset($h[$s-1]);
- $huruf=implode('',$h);
- }
- $t2 = MICROTIME(TRUE);
- $dt[$p]['t']=$t2-$t1;
- echo "\nMakan waktu: ".$dt[$p]['t']." sekon\n";
- //===
- $p=5;
- $dt[$p]['n']='Ahmad Anang Atmahadli *';
- echo "===\nAhmad Anang Atmahadli *\n";
- $t1 = MICROTIME(TRUE);
- $angka=_ANGKA;
- $huruf=_HURUF;
- while(!empty($huruf)){
- $h=str_split($huruf);
- $n=strlen($huruf);
- $s=($angka%$n)?$angka%$n:$n;
- echo $h[$s-1];
- unset($h[$s-1]);
- $huruf=implode('',$h);
- }
- $t2 = MICROTIME(TRUE);
- $dt[$p]['t']=$t2-$t1;
- echo "\nMakan waktu: ".$dt[$p]['t']." sekon\n";
- //==
- /*
- echo "===\nGanjar Setia M \n";
- echo "</pre>";
- $t1 = MICROTIME(TRUE);
- $angka = 8;
- $huruf = array('a','b','c','d','e','f');
- $temp1 = '';
- $j = 0;
- $outputnya = '';
- $sizeHuruf = count($huruf);
- for ($loop1 = 1; $loop1 <= $sizeHuruf; $loop1++) {
- for ($i = 1; $i <= $angka; $i++) {
- if ($i <= count($huruf)) {
- echo $huruf[$i-1]." = ".$i."<br/>";
- } elseif ($j < count($huruf)) {
- echo $huruf[$j]." = ".$i."<br/>";
- $j++;
- } else {
- $j = 0;
- echo $huruf[$j]." = ".$i."<br/>";
- $j++;
- }
- if ($i == $angka) {
- $j--;
- $outputnya .= $huruf[$j];
- array_splice($huruf, $j, 1);
- }
- }
- $j = 0;
- echo "<br/>Ini Outputnya:<br/>" . $outputnya . "<br/><br/>";
- }
- echo "<pre>";
- $t2 = MICROTIME(TRUE);
- $dt[$p]['t']=$t2-$t1;
- echo "\nMakan waktu: ".$dt[$p]['t']." sekon\n";
- */
- //==
- $p=6;
- $dt[$p]['n']='Ganjar Setia M *';
- echo "===\nGanjar Setia M *\n";
- $t1 = MICROTIME(TRUE);
- $angka = _ANGKA;
- $huruf = str_split(_HURUF);
- $temp1 = '';
- $j = 0;
- $outputnya = '';
- $sizeHuruf = count($huruf);
- for ($loop1 = 1; $loop1 <= $sizeHuruf; $loop1++) {
- for ($i = 1; $i <= $angka; $i++) {
- $c=count($huruf);
- if ($i <= $c) {
- } elseif ($j < $c) {
- $j++;
- } else {
- $j = 1;
- }
- if ($i == $angka) {
- $j--;
- echo $huruf[$j];
- array_splice($huruf, $j, 1);
- }
- }
- $j = 0;
- }
- $t2 = MICROTIME(TRUE);
- $dt[$p]['t']=$t2-$t1;
- echo "\nMakan waktu: ".$dt[$p]['t']." sekon\n";
- //==
- $p=7;
- $dt[$p]['n']='Nandang Permana #1';
- echo "===\nNandang Permana #1\n";
- $t1 = MICROTIME(TRUE);
- $angka = _ANGKA;
- $huruf = str_split(_HURUF);
- $hasil = "";
- $temp ="";
- $jumlah_huruf = count($huruf);
- for($i=0;$i<=$jumlah_huruf-1;$i++)
- {
- $huruf = array_values($huruf);
- if( ($angka > count($huruf)) && (($angka%count($huruf))!=0) )
- {
- $temp = $huruf[($angka%(count($huruf))-1)];
- }
- else if(($angka%count($huruf))==0)
- {
- $temp = $huruf[count($huruf)-1];
- }
- else
- {
- $temp = $huruf[$angka-1];
- }
- $hasil = $hasil.$temp;
- if(($key = array_search($temp, $huruf)) !== false) {
- unset($huruf[$key]);
- }
- }
- echo $hasil;
- $t2 = MICROTIME(TRUE);
- $dt[$p]['t']=$t2-$t1;
- echo "\nMakan waktu: ".$dt[$p]['t']." sekon\n";
- //==
- $p=8;
- $dt[$p]['n']='Nandang Permana #1 *';
- echo "===\nNandang Permana #1 *\n";
- $t1 = MICROTIME(TRUE);
- $angka = _ANGKA;
- $huruf = str_split(_HURUF);
- $hasil = "";
- $temp ="";
- $jumlah_huruf = count($huruf);
- for($i=0;$i<=$jumlah_huruf-1;$i++)
- {
- $c=count($huruf);
- $huruf = array_values($huruf);
- $temp =($angka%$c==0?$huruf[$c-1]:($angka > $c?$huruf[$angka%$c-1]:$huruf[$angka-1]));
- $hasil .=$temp;
- if(($key = array_search($temp, $huruf)) !== false) {
- unset($huruf[$key]);
- }
- }
- echo $hasil;
- $t2 = MICROTIME(TRUE);
- $dt[$p]['t']=$t2-$t1;
- echo "\nMakan waktu: ".$dt[$p]['t']." sekon\n";
- //==
- $p=9;
- $dt[$p]['n']='Verri Andriawan';
- echo "===\nVerri Andriawan\n";
- $t1 = MICROTIME(TRUE);
- $angka=_ANGKA;
- $huruf=_HURUF;$i=0;$j=0;
- $temp='';
- while(strlen($huruf)>0){
- if(!isset($huruf[$j]))$j=0;
- $i++;
- if($i>=$angka){
- $temp.=$huruf[$j];
- $huruf[$j]=' ';
- $huruf=preg_replace('/\s/','',$huruf);
- }
- $j++;
- if($i>=$angka)$i=$j=0;
- }
- $huruf=$temp;
- echo $huruf;
- $t2 = MICROTIME(TRUE);
- $dt[$p]['t']=$t2-$t1;
- echo "\nMakan waktu: ".$dt[$p]['t']." sekon\n";
- //==
- $p=10;
- $dt[$p]['n']='Verri Andriawan *';
- echo "===\nVerri Andriawan *\n";
- $t1 = MICROTIME(TRUE);
- $angka=_ANGKA;
- $huruf=_HURUF;
- $i=$j=0;
- $temp='';
- while(!empty($huruf)){
- if(!isset($huruf[$j]))$j=0;
- $i++;
- if($i>=$angka){
- $temp.=$huruf[$j];
- $huruf[$j]=' ';
- $huruf=str_replace(' ','',$huruf);
- }
- $j++;
- if($i>=$angka)$i=$j=0;
- }
- echo $temp;
- $t2 = MICROTIME(TRUE);
- $dt[$p]['t']=$t2-$t1;
- echo "\nMakan waktu: ".$dt[$p]['t']." sekon\n";
- //==
- $p=11;
- $dt[$p]['n']='Share Yo';
- echo "===\nShare Yo\n";
- $t1 = MICROTIME(TRUE);
- $angka=_ANGKA;
- $huruf=_HURUF;
- function repos_str(&$str,$n){
- $r="";
- while ($l=strlen($str)){
- $s=$n%$l-1;
- if($s<0)$s=$l-1;
- $r.=$str[$s];
- $str=substr_replace($str,"",$s,1);
- }
- return $r;
- }
- echo repos_str($huruf,$angka);
- $t2 = MICROTIME(TRUE);
- $dt[$p]['t']=$t2-$t1;
- echo "\nMakan waktu: ".$dt[$p]['t']." sekon\n";
- //==
- $p=12;
- $dt[$p]['n']='Share Yo *';
- echo "===\nShare Yo*\n";
- $t1 = MICROTIME(TRUE);
- $angka=_ANGKA;
- $huruf=_HURUF;
- $r="";
- while ($l=strlen($huruf)){
- $s=$angka%$l-1<0?$l-1:$angka%$l-1;
- $r.=$huruf[$s];
- $huruf=substr_replace($huruf,"",$s,1);
- }
- echo $r;
- $t2 = MICROTIME(TRUE);
- $dt[$p]['t']=$t2-$t1;
- echo "\nMakan waktu: ".$dt[$p]['t']." sekon\n";
- //==
- $p=13;
- $dt[$p]['n']='Nandang Permana #2';
- echo "===\nNandang Permana #2\n";
- $t1 = MICROTIME(TRUE);
- $angka = _ANGKA;
- $huruf = str_split(_HURUF);
- $hasil = "";
- $key = 0;
- $jumlah_huruf = count($huruf);
- for($i=0;$i<=$jumlah_huruf-1;$i++)
- {
- $c=count($huruf);
- $huruf = array_values($huruf);
- $key =($angka%$c==0?$c-1:($angka > $c?$angka%$c-1:$angka-1));
- $hasil .= $huruf[$key];
- unset($huruf[$key]);
- }
- echo $hasil;
- $t2 = MICROTIME(TRUE);
- $dt[$p]['t']=$t2-$t1;
- echo "\nMakan waktu: ".$dt[$p]['t']." sekon\n";
- //==
- $p=14;
- $dt[$p]['n']='Chakoo Chandra #1';
- echo "===\nChakoo Chandra #1\n";
- $t1 = MICROTIME(TRUE);
- $angka = _ANGKA;
- $huruf = _HURUF;
- recur($huruf, $angka, '');
- function recur($huruf, $angka, $ch) {
- $idx = $angka % strlen($huruf) - 1;
- if ($idx < 0)
- $idx = strlen($huruf) - 1;
- $char = substr($huruf, $idx, 1);
- $huruf = str_replace($char, '', $huruf);
- $ch.=$char;
- if (strlen($huruf) > 0) {
- recur($huruf, $angka, $ch);
- } else {
- echo $ch;
- }
- }
- $t2 = MICROTIME(TRUE);
- $dt[$p]['t']=$t2-$t1;
- echo "\nMakan waktu: ".$dt[$p]['t']." sekon\n";
- //==
- $p=15;
- $dt[$p]['n']='Chakoo Chandra #2';
- echo "===\nChakoo Chandra #2\n";
- $t1 = MICROTIME(TRUE);
- $angka = _ANGKA;
- $huruf = _HURUF;
- $arr_huruf = str_split($huruf);
- recur2($arr_huruf, $angka,'');
- function recur2($huruf, $angka,$ch) {
- $idx = $angka % count($huruf) - 1;
- if ($idx < 0)
- $idx = count($huruf) - 1;
- $char=array_splice($huruf, $idx, 1);
- $ch.=$char[0];
- if (count($huruf) > 0) {
- recur2($huruf, $angka,$ch);
- } else {
- echo $ch;
- }
- }
- $t2 = MICROTIME(TRUE);
- $dt[$p]['t']=$t2-$t1;
- echo "\nMakan waktu: ".$dt[$p]['t']." sekon\n";
- //==
- $p=16;
- $dt[$p]['n']='Maman Wae *';
- echo "===\nMaman Wae *\n";
- $t1 = MICROTIME(TRUE);
- $angka = _ANGKA;
- $huruf = _HURUF;
- $a=$b=0;$output='';//--inisialisasi
- while (strlen($huruf)>0){
- $a++;
- $b++;
- $x = strlen($huruf);
- if($b==$angka){
- $output .= substr($huruf,$a-1,1);
- $huruf = str_replace(substr($huruf,$a-1,1),'',$huruf);
- $a = 0;
- $b = 0;
- }
- if ($a==$x) $a = 0;
- }
- echo $output;
- $t2 = MICROTIME(TRUE);
- $dt[$p]['t']=$t2-$t1;
- echo "\nMakan waktu: ".$dt[$p]['t']." sekon\n";
- //===
- echo "===\nGRAND RESULT\n";
- foreach ($dt as $key => $row) {
- $_name[$key] = $row['n'];
- $_time[$key] = $row['t'];
- }
- array_multisort($_time, SORT_ASC, $_name, SORT_ASC, $dt);
- $no=1;
- foreach($dt as $data){
- echo str_pad($no,3,' ',STR_PAD_LEFT).". "
- .str_pad($data['n'],28,' ')
- .str_pad($data['t'],24,' ',STR_PAD_LEFT)."\n";
- $no++;
- }
- echo "===\n)* modified";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement