Code of rikul
<?php
set_time_limit
(60);

$fd = fopen("deck.txt", "r");
$sfl_str = fread ($fd, filesize ("deck.txt"));
fclose ($fd);

$sfl_str = trim($sfl_str);
$un_sfl_str = "";
$half_len = 0;
$len = 0;
$counter = 0;

function 
sfl($str)
{
    global 
$len, $half_len;

    
$tmp="";
    for(
$i=0, $j=$half_len; $j<$len; $i++,$j++)
        
$tmp .= $str[$j] . $str[$i];

    return 
$tmp;
}


function 
cut($str)
{
    global 
$len,$half_len;
    
    return 
substr($str, $half_len, $len) . substr($str,0,$half_len);
}


function 
flip($str)
{
    return 
strrev($str);
}

function 
get_unsfl_str()
{
    global 
$len, $half_len;
    
$tmp = "";
    for(
$i=ord('A'); $i<ord('A')+$half_len; $i++)
        
$tmp .= chr($i);

    for(
$i=ord('a'); $i<ord('a')+$half_len; $i++)
        
$tmp .= chr($i);

    return 
$tmp;
}

function 
find_sol($str, $sol, $max_sol_len)
{
    global 
$un_sfl_str, $len, $half_len, $seen_array, $sfl_str;
    
    if (
$str == $un_sfl_str)
    {
        print 
"$sol" . strlen($sol);
        exit;
    }

    
$sol_len = strlen($sol);
    
//print "$str $sol $sol_len $max_sol_len\n";
    
    
if ($sol_len > $max_sol_len)
        return;
    
    
$op = "sfl"; $op_str = "S";
    
$s = $op($str);
    
find_sol($s, $sol . $op_str, $max_sol_len );

    
$op = "flip"; $op_str = "F";
    
$s = $op($str);
    
find_sol($s, $sol . $op_str, $max_sol_len);

    
$op = "cut"; $op_str = "C";
    
$s = $op($str);
    
find_sol($s, $sol . $op_str, $max_sol_len);

}


$seen_array = array();
$len = strlen($sfl_str);
$half_len = $len/2;
$un_sfl_str = get_unsfl_str();

for(
$i=1; $i <= $len * 2; $i++)
{
    
find_sol($sfl_str, "",$i);
}

?>


Back to results


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