Code of vlad
<?
/****************************************************************
   (c) Vladislav Shudegov 
   vlad@samba.ru
****************************************************************/
    
    
$file_name='deck.txt';

    
$direction=array(
        
'C'=>array('S''F'),
        
'S'=>array('C''S''F'),
        
'F'=>array('C''S')
    );

    
$ideal_upper='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    
$ideal_lower='abcdefghijklmnopqrstuvwxyz';

    
$input freadfopen($file_name'r'), filesize($file_name) );

    
$half_len=strlen($input)/2;
    
$must_be=substr($ideal_upper0$half_len).substr($ideal_lower0$half_len);

    if (
$input==$must_be)
    {
        echo 
'0';
        exit;
    }

    
$was=array(
                
$input => 1
        
);      

    
$front=array(
        
0=>array(
                
'history'       =>'',
                
'result'        =>$input,
                
'operation'     =>'S'
        
)       
    );

    while (
count($front))
    {
        
$new_front=array();
        foreach(
$front as $i=>$item)
        {
                foreach(
$direction[$item['operation']] as $operation)
                {
                        switch(
$operation)
                        {
                                case 
'C'$result deck_cut($item['result']);
                                                  break;
                                case 
'F'$result deck_flip($item['result']);
                                                  break;
                                case 
'S'$result deck_shuffle($item['result']);
                                                  break;
                        }

                        if (!isset(
$was[$result]))
                        {
                                if (
$result==$must_be)
                                {
                                        echo 
$item['history'].$operation.' '.strlen($item['history'].$operation);
                                           exit;
                                }

                                
$was[$result]=1;
                                
$new_front[]=array(
                                                                
'history'       =>$item['history'].$operation,
                                                                
'result'        =>$result,
                                                                
'operation'     =>$operation
                                                         
);
                        }
                }
        }
        
$front=$new_front;
    }
    echo 
'Hmm';


    function 
deck_cut($in)
    {   global 
$half_len;

        return 
substr($in$half_len$half_len).substr($in0$half_len);
    }


    function 
deck_flip($in)
    {   
        return 
strrev($in);
    }


    function 
deck_shuffle($in)
    {   global 
$half_len;

        
$res='';
        for(
$i=0$i<$half_len$i++)
        {
                
$res.=substr($in$half_len+$i1).substr($in$i1);
        }
        return 
$res;
    }
?>


Back to results


© Copyright 2003-2023 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.