Created
September 24, 2019 04:57
-
-
Save unique1984/6e9588e4611b3ebd107b72cdd1fd51c9 to your computer and use it in GitHub Desktop.
Verilen dizi elemanlarının kombinasyonları.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting(E_ALL); | |
ini_set("display_errors", 1); | |
$start = microtime(true); | |
$start_memory = memory_get_usage(); | |
$range = range(0, 100); | |
//~ $range = array(10, 20, 30, 40, 50); | |
shuffle($range); | |
$copy = $range; | |
$all = array(); | |
echo "<pre>"; | |
// dizinin her bir elemanı için, | |
for ($i=0; $i<count($range); $i++) { | |
// ilk elemanı ayır, | |
$shift = array_shift($copy); | |
for ($j=0; $j<count($copy); $j++) { | |
// kopya dizinin ilk elemanını ayır, | |
$innerShift = array_shift($copy); | |
// ilk ayrım, ikinci ayrım, kalanı yazdır (burada elemanlar ile farklı bir işlem yapmak istersen sana kalmış.) | |
/* | |
* Oluşan dizi, 80M civarı belleğe yükleniyor. | |
* Kontrol yapılarını buraya ekleyip $all dizisini sınırlamak mantıklı gibi... | |
* */ | |
//~ $all[] = array_merge([$shift, $innerShift], $copy); | |
echo $shift . " " . $innerShift . " " . implode(" ", $copy) . "\n"; | |
// ayırdığın elemanı sona ekleyerek birleştir. | |
array_push($copy, $innerShift); | |
} | |
// ayırdığın elemanı sona ekleyerek birleştir. | |
array_push($copy, $shift); | |
} | |
//~ print_r($all); | |
$end = microtime(true); | |
$end_memory = memory_get_usage(); | |
echo round(($end-$start)*1000, 2) . "ms\n"; | |
echo round(($end_memory-$start_memory)/1024, 2) . "Kb\n"; | |
echo "</pre>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.facebook.com/groups/trlinux/permalink/2184251988347498/