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); return implode("", $result); } $r = array(); //$letters = 'abcdefghijklm'; $letters = 'abcdefgh'; $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)); array_unique($r, SORT_REGULAR) print_r(count($r));
Output for 5.4.0 - 5.4.28
Parse error: syntax error, unexpected 'print_r' (T_STRING) in /in/BgVXL on line 39
Process exited with code 255.
Output for 5.3.0 - 5.3.28
Parse error: syntax error, unexpected T_STRING in /in/BgVXL on line 39
Process exited with code 255.

preferences:
182.63 ms | 1395 KiB | 65 Q