3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Returns the total number of $count-length strings generatable from $letters. function getPermCount($letters, $count) { $result = 1; // k characters from a set of n has n!/(n-k)! possible combinations for($i = strlen($letters) - $count + 1; $i <= strlen($letters); $i++) { $result *= $i; } return $result; } // Decodes $index to a $count-length string from $letters, no repeat chars. function getPerm($letters, $count, $index) { $result = array(); for($i = 0; $i < $count; $i++) { $pos = $index % strlen($letters); $result[] = $letters[$pos]; $index = ($index-$pos)/strlen($letters); $letters = substr($letters, 0, $pos) . substr($letters, $pos+1); } sort($result); $result = array_unique($result, SORT_REGULAR); return implode("", $result); } $r = array(); //$letters = 'abcdefghijklm'; $letters = 'abcdefghi'; $len = strlen($letters); for ($c = 1; $c <= $len; $c++) { for($i = 0; $i < getPermCount($letters, $c); $i++) $r[] = getPerm($letters, $c, $i); } //print_r(array_unique($r, SORT_REGULAR)); $r = array_unique($r, SORT_REGULAR); print_r(count($r));
Output for git.master, rfc.property-hooks
Fatal error: Out of memory (allocated 29364224 bytes) (tried to allocate 16777224 bytes) in /in/Gok47 on line 36 mmap() failed: [12] Cannot allocate memory mmap() failed: [12] Cannot allocate memory
Process exited with code 255.
Output for git.master_jit
Fatal error: Out of memory (allocated 14684160 bytes) (tried to allocate 8388616 bytes) in /in/Gok47 on line 36 mmap() failed: [12] Cannot allocate memory mmap() failed: [12] Cannot allocate memory
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
43.93 ms | 401 KiB | 8 Q