예제 #1
0
파일: Brackets.php 프로젝트: dukle/codility
function solution($A)
{
    $sizeOfString = strlen($A);
    $i = 0;
    $j = 0;
    $B = array();
    while ($i < $sizeOfString) {
        if (!isset($B[$j])) {
            $B[$j] = $A[$i];
            $i++;
        } else {
            //            var_dump("***");
            //            var_dump("$i: $A[$i] - " .complement($A[$i]));
            if (complement($A[$i]) == $B[$j]) {
                array_pop($B);
                if ($j > 0) {
                    $j--;
                }
            } else {
                array_push($B, $A[$i]);
                $j++;
            }
            $i++;
        }
    }
    if (sizeOf($B) > 0 || $sizeOfString == 0) {
        return 0;
    } else {
        return 1;
    }
}
예제 #2
0
 public function testComplement()
 {
     $isEmpty = function ($x) {
         return empty($x);
     };
     // empty is not callable
     $notEmpty = complement($isEmpty);
     $this->assertTrue($notEmpty("something"));
     $this->assertFalse($notEmpty(""));
 }
예제 #3
0
 function readInt32BE($i)
 {
     $v = $this->readUInt32BE($i);
     if (($v & 2147483648.0) !== 0) {
         return -complement($v, 32);
     }
     return $v;
 }
예제 #4
0
파일: lib.php 프로젝트: blackwood/vervel
/**
 * Returns true if number is odd.
 */
function odd($n)
{
    $odd = complement('v\\even');
    return $odd($n);
}