Example #1
0
 public static function canResize($imagePath)
 {
     $pictureInfo = getimagesize($imagePath);
     $memoryNeeded = round(($pictureInfo[0] * $pictureInfo[1] * $pictureInfo['bits'] * $pictureInfo['channels'] / 8 + Math::power(2, 16)) * 1.65);
     $memoryLimit = str_replace('M', '', Config::getMemoryLimit()) * Math::power(2, 20);
     return $memoryLimit > $memoryNeeded + memory_get_usage(TRUE) ? TRUE : FALSE;
 }
Example #2
0
 public function multiply($a, $b)
 {
     $times = Math::absSystem($b);
     for ($i = 0; $i < $times; $i++) {
         $a += $a;
     }
     return $b > 0 ? $a : -$a;
 }
Example #3
0
 public static function fisherYates($data)
 {
     $size = count($data);
     foreach ($data as $k => $v) {
         $index = Math::randomInterval(0, $size);
         self::swap($data, $k, $index);
     }
     return $data;
 }
Example #4
0
 public static function newId()
 {
     usleep(Math::randomInterval(2, 4) * 100);
     for ($i = 0; $i < Math::randomInterval(2, 5); $i++) {
         usleep(100);
         session_regenerate_id(TRUE);
         usleep(100);
     }
     usleep(Math::randomInterval(2, 4) * 100);
     return self::id();
 }
Example #5
0
 public final function getDepth(AbstractBinaryTree $root = NULL)
 {
     if ($root == NULL) {
         return -1;
     }
     if ($root instanceof TernaryTree) {
         return 1 + Math::max($this->getDepth($root->left), $this->getDepth($root->middle), $this->getDepth($root->right));
     } else {
         return 1 + Math::max($this->getDepth($root->left), $this->getDepth($root->right));
     }
 }
Example #6
0
 public function __construct($width = 400, $height = 200)
 {
     parent::__construct();
     if (!Validator::isNumber($width) || Validator::isNumber($height)) {
         throw new IllegalArgumentException();
     }
     $this->captcha = new Images($width, $height);
     $this->captcha->setBackgroundColor(new Color(0, 0, 0));
     $this->captcha->setTextColor(new Color(255, 255, 255));
     $string = new StringW(Hash::r());
     $this->text = $string->subString(0, Math::randomInterval(6, 8));
     $this->captcha->setText(Math::randomInterval(2, 6), new Point(0, 0), $string, FALSE);
 }
Example #7
0
 public function index()
 {
     $ipString = '2001:4cfb:bfc4:0000:0000:0000:0123:4aab';
     $myIP = new IPv6("2001:4cfb:0000:0000:0000:0000:0123:4aab", FALSE);
     //$myIP = new IPv4( '1.2.3.4', TRUE );
     $myIP = new IPvU($ipString, FALSE);
     //$myIP = new IPvU( "1.2.3.4", FALSE);
     echo ' IPString=' . $ipString . '<br>';
     echo 'MY IP=' . $myIP->getNiceIP() . '<br>';
     $z = new StringW("aookkooa");
     echo 'Text:<b>' . $z . '</b><br>Longest palindrome using Manachers algorithm: <b>' . $z->getLongestPalindromeManacher() . '</b>';
     $this->getDB()->query('SELECT user_name FROM users LIMIT 50;', []);
     $res = $this->getDB()->fetchAll();
     $this->getDB()->freeStatement();
     echo 'ack2:' . Math::ackermannLimitedRecoursion(3, 88);
     //echo 'ack:' . Math::ackermann( 3, 17 );
     return $res;
 }
Example #8
0
 public static function solveQuadraticEquation($a, $b, $c)
 {
     if ($b == 0 && $c <= 0) {
         $c = Math::absSystem($c);
         $c /= $a;
         $cSqrt = Math::squareRoot($c);
         return [0 => $cSqrt, 1 => -$cSqrt];
     }
     $d = self::discriminant2($a, $b, $c);
     if ($d < 0) {
         return NULL;
     } else {
         if ($d == 0 || $a == 0) {
             return [0 => -$b / 2 * $a, 1 => NULL];
         } else {
             return [0 => -$b + Math::squareRoot($d) / (2 * $a), 1 => -$b - Math::squareRoot($d) / (2 * $a)];
         }
     }
 }
Example #9
0
 public function numberPower($number)
 {
     if (!Validator::isNumber($number)) {
         throw new IllegalArgumentException();
     }
     $newMatrix = [];
     for ($i = 0; $i < $this->getMatrixSizeA(); $i++) {
         for ($j = 0; $j < $this->getMatrixSizeB(); $j++) {
             $newMatrix[$i][$j] = Math::power($this->getMatrix()[$i][$j], $number);
         }
     }
     return new Matrix($newMatrix);
 }
Example #10
0
 public function getRedHexa()
 {
     return Math::decimalToHexadecimal($this->red);
 }
Example #11
0
 public static function rNum()
 {
     return Math::randomInterval(0, Math::randomInterval(1, Math::randomInterval(2, 1000)));
 }
Example #12
0
 protected function sort(AbstractSort $sort)
 {
     $maxDepth = Math::logarithmDecade(count($this->originalData)) * 2;
     $this->sortedData = $this->introsort($this->originalData, $maxDepth);
 }
Example #13
0
print_r($arrray);
$ms = new \QW\FW\DataWorking\Sort\MergeSort($arrray);
echo '<br><br>UNSORTED:::<br><br>';
print_r($ms->getOriginalArray());
echo '<br><br>SORTED BY MERGE SORT:::<br><br>';
print_r($ms->getSortedArray());
/*
echo 'try Ackermann function:';
echo Math::ackermann( 2, 5 );

echo '<br>Finding Ackermnann inv:<br>';

Math::ackermannInv( 125 )
	->printMatrix();
*/
echo '<br>';
var_dump(Math::randomBoolean());
$root = new TernaryTree(new BinaryTree(NULL, NULL, 1), new BinaryTree(NULL, NULL, 2), new BinaryTree(NULL, NULL, 3), 4, FALSE);
echo 'Z------';
print_r($root->iteratorEulerTour()->getFinalData());
$root = NULL;
$root3 = new TernaryTree(new TernaryTree(NULL, NULL, NULL, 2), new TernaryTree(NULL, NULL, NULL, 3), new TernaryTree(new TernaryTree(NULL, NULL, NULL, 5), new TernaryTree(NULL, NULL, NULL, 6), NULL, 4), 1);
echo 'Euler TERNARY:<br>';
print_r($root3->iteratorEulerTour()->getFinalData());
$root3 = NULL;
$root4 = new \QW\FW\DataStructures\Trees\Nary\NaryTree([new \QW\FW\DataStructures\Trees\Nary\NaryTree([], 3), new \QW\FW\DataStructures\Trees\Nary\NaryTree([], 3), new \QW\FW\DataStructures\Trees\Nary\NaryTree([new \QW\FW\DataStructures\Trees\Nary\NaryTree([], 5), new \QW\FW\DataStructures\Trees\Nary\NaryTree([], 6)], 4)], 1);
$root4 = NULL;
?>


Example #14
0
 public static function randomBoolean()
 {
     return new Boolean(Math::randomBoolean());
 }
Example #15
0
 public static function sieveOfEratosthenes($number)
 {
     $sieve = [];
     $sieve[0] = $sieve[1] = TRUE;
     $squareRoot = Math::squareRoot($number);
     for ($i = 2; $i <= $squareRoot; $i++) {
         if ($sieve[$i] == TRUE) {
             continue;
         }
         for ($j = 2 * $i; $j < $number; $j += $i) {
             $sieve[$j] = TRUE;
         }
     }
     return $sieve;
 }
Example #16
0
 public function subString($start, $end = NULL)
 {
     return new StringW(mb_substr($this->string, Math::max(0, $start), Math::max(0, Math::min(Math::max(0, $end), $this->getLength() - 1)), self::UTF8));
 }
Example #17
0
 public static function getFibonacci($x)
 {
     static $gro5;
     $gro5 = Math::squareRoot(5);
     $fi = (1 + $gro5) / 2;
     return Math::power($fi, $x) / $gro5 - Math::power(1 - $fi, $x) / $gro5;
 }
Example #18
0
 public function sin()
 {
     return new MathComplexNumber(Math::sin($this->real) * Math::cosH($this->imaginary), Math::cos($this->real) * Math::sinH($this->imaginary));
 }
Example #19
0
 public function getDepth(AbstractBinaryTree $root = NULL)
 {
     if ($root == NULL) {
         return -1;
     }
     return Math::max($this->getDepth($root->left), $this->getDepth($root->right)) + 1;
 }