<?php
$f = 'CAN,CBN';
$words = explode(',', $f);
$a = $ao = $words[0];
$b = $bo = $words[1];
$win = '';
function splice($a,$cut) {
$total = $high = 0;
$ret = array();
$arr = str_split($a);
foreach ($arr as $key => $value) {
$total = $total + ord($value) - 64;
if ($value > $high){$high = $key;}
}
$ret[0]=$total;
if ($cut) { unset($arr[$high1]); $ret[1] = $arr; }
return $ret;
}
while($win=='') {
$ret1 = splice($a,FALSE);
$ret2 = splice($b,FALSE);
$ret3 = splice($ret1[0],TRUE);
$ret4 = splice($ret2[0],TRUE);
if($ret3[0] > $ret4[0]) {
$win = $ao;
} else if ($ret3[0] < $ret4[0]) {
$win = $bo;
} else if ((strlen($a)<1) OR (strlen($b)<1)) {
if (strlen($a) < strlen($b)) { $win = $ao; }
else if (strlen($b) < strlen($a)) { $win = $bo; }
else { $win = 'STALEMATE'; }
}
}
echo $win;
?>