Project Euler Solutions by Ross Marks

<?php
/*****************************
 * ProjectEuler - Problem 24
 * By Ross Marks
 *****************************
 * A permutation is an ordered arrangement of objects. For example, 3124 is one possible permutation of the digits 1, 2, 3 and 4. If all of the permutations are listed numerically or alphabetically, we call it lexicographic order. The lexicographic permutations of 0, 1 and 2 are:
 * 
 * 012   021   102   120   201   210
 * 
 * What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?
 ****************************/

//$perm_array = pc_permute(array(0, 1, 2, 3, 4, 5, 7, 8, 9));
$count 1;

function 
pc_permute($items$perms = array( )) {
    global 
$count;
    if (empty(
$items)) { 
        print 
$count." - ".join(' '$perms) . "\n";
        
$count++;
    }  else {
        for (
$i count($items) - 1$i >= 0; --$i) {
             
$newitems $items;
             
$newperms $perms;
             list(
$foo) = array_splice($newitems$i1);
             
array_unshift($newperms$foo);
             
pc_permute($newitems$newperms);
         }
    }
}

function 
pc_permute2($items$perms = [],&$ret = []) {
    
//global $count;
   
if (empty($items)) {
       
$ret[] = $perms;
       
//print $count." - ".join(' ', $perms) . "\n";
       //$count++;
   
} else {
       for (
$i count($items) - 1$i >= 0; --$i) {
           
$newitems $items;
           
$newperms $perms;
           list(
$foo) = array_splice($newitems$i1);
           
array_unshift($newperms$foo);
           
pc_permute2($newitems$newperms,$ret);
       }
   }
   return 
$ret;
}

echo 
"[+] Creating permutations\n";
$options = ['1','2','3','4','5','6','7','8','9','0'];
$x pc_permute2($options);

echo 
"[+] Sorting permutations\n";
sort($x);

echo 
"Awnser: ";
echo 
$x[1000000-1][0];
echo 
$x[1000000-1][1];
echo 
$x[1000000-1][2];
echo 
$x[1000000-1][3];
echo 
$x[1000000-1][4];
echo 
$x[1000000-1][5];
echo 
$x[1000000-1][6];
echo 
$x[1000000-1][7];
echo 
$x[1000000-1][8];
echo 
$x[1000000-1][9];

?>