codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
<?php $f = 'CAN,CBN'; $words = explode(',', $f); $a = $words[0]; $b = $words[1]; $ao = $a; $bo = $b; // echo (ord($a)-64); $high1 = 0; $high2 = 0; $total1 = 0; $total2 = 0; $total3 = 0; $win = ''; while($win=='') { $arr1 = str_split($a); foreach ($arr1 as $key => $value) { $total1 = $total1 + ord($value) - 64; } $arr2 = str_split($b); foreach ($arr2 as $key => $value) { $total2 = $total2 + ord($value) - 64; } $arr3 = str_split($total1); foreach ($arr3 as $key => $value) { $total3 = $total3 + $value; if ($value > $high1){ $high1 = $key; } } $arr4 = str_split($total2); foreach ($arr4 as $key => $value) { $total4 = $total4 + $value; if ($value > $high2){ $high2 = $key; } } if($total3 > $total4) { $win = $ao; } else if ($total4 > $total3) { $win = $bo; } else if ((strlen($a)==1) OR (strlen($b)==1)) { $win = 'STALEMATE'; } else { unset($arr1[$high1]); unset($arr2[$high2]); $a = implode($arr1); $b = implode($arr2); } } echo $win; ?>
Private
[
?
]
Run code
Submit