Code of boris
<?php
function C($x) {
global $half;
return substr($x, $half).substr($x, 0, $half);
}
function F($x) {
global $len;
$r = "";
for ($i = $len-1; $i >=0; $i--) {
$r .= substr($x, $i, 1);
}
return $r;
}
function S($x) {
global $half;
$r = "";
for ($i = 0; $i < $half; $i++) {
$r .= substr($x, $half+$i, 1) . substr($x, $i, 1);
}
return $r;
}
$start = trim(implode("",file("deck.txt")));
$len = strlen($start);
$half = $len/2;
$seen = array();
$t_arr = preg_split('//', $start, -1, PREG_SPLIT_NO_EMPTY);
sort($t_arr);
$target = implode("", $t_arr);
$seen[''] = $start;
while(1) {
foreach ($seen as $k => $v) {
foreach (array("F","C","S") as $f) {
$nval = call_user_func($f,$v);
if (array_search($nval, $seen) === false) { /* new value */
$seen[$k.$f] = $nval;
/* echo "$v - $f - $nval\n"; */
if ($nval == $target) {
echo "$k$f ".strlen("$k$f")."\n";
exit;
}
}
}
}
}
?>
Back to results
|
|