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 = 'abcdefghij'; $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 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Fatal error: Out of memory (allocated 27267072 bytes) (tried to allocate 16777224 bytes) in /in/Yhn7R on line 36 mmap() failed: [12] Cannot allocate memory mmap() failed: [12] Cannot allocate memory
Process exited with code 255.
Output for 8.1.2 - 8.1.27
Fatal error: Out of memory (allocated 18878464) (tried to allocate 16777224 bytes) in /in/Yhn7R on line 36 mmap() failed: [12] Cannot allocate memory mmap() failed: [12] Cannot allocate memory
Process exited with code 255.
Output for 7.2.29 - 7.2.33, 7.3.16 - 7.3.25, 7.3.27 - 7.3.31, 7.4.3 - 7.4.25, 7.4.27 - 7.4.33, 8.0.0 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.1
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 33554440 bytes) in /in/Yhn7R on line 36
Process exited with code 255.
Output for 8.0.13
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 67108872 bytes) in /in/Yhn7R on line 36
Process exited with code 255.
Output for 7.3.26, 7.3.32 - 7.3.33, 7.4.26

Process exited with code 137.
Output for 5.3.0 - 5.3.10, 5.4.0 - 5.4.28
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 79 bytes) in /in/Yhn7R on line 26
Process exited with code 255.
Output for 5.3.11 - 5.3.28
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 71 bytes) in /in/Yhn7R on line 25
Process exited with code 255.

preferences:
160.24 ms | 401 KiB | 194 Q