Created
October 20, 2017 16:37
-
-
Save jordi-pascual/457136724f757825b224a550ec76a651 to your computer and use it in GitHub Desktop.
Permutation
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
function pc_permute($items, $perms = array( )) { | |
if (empty($items)) { | |
print join(' ', $perms) . "\n"; | |
} else { | |
for ($i = count($items) - 1; $i >= 0; --$i) { | |
$newitems = $items; | |
$newperms = $perms; | |
list($foo) = array_splice($newitems, $i, 1); | |
array_unshift($newperms, $foo); | |
pc_permute($newitems, $newperms); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment