Skip to content

Instantly share code, notes, and snippets.

@leafnode
Created May 26, 2015 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leafnode/69cd0052ea836b378d9e to your computer and use it in GitHub Desktop.
Save leafnode/69cd0052ea836b378d9e to your computer and use it in GitHub Desktop.
<?php
function pc_permute($items, $perms = array( )) {
if (empty($items)) {
$res = $perms[0] + 13.0 * $perms[1] / $perms[2] + $perms[3] + 12.0 * $perms[4] - $perms[5] - 11.0 + $perms[6] * $perms[7] / $perms[8] - 10.0;
if ($res == 66.0) {
print join(' ', $perms) . ": $res\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);
}
}
}
$iv = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0];
pc_permute($iv);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment