3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<? class BigAndSmallStep { public $f; public $b; public $n; public $a; public $L1 = array(); public $L2 = array(); public $findStr; public $result; public function __construct ($f, $b, $n) { $this->f = intval($f); $this->b = intval($b); $this->n = intval($n); $this->a = self::countA($this->n); } function countA($n) { return ceil(sqrt($n)); } function countL1() { $c = $this->a-1; $i = 0; while ( $i <= $c) { $heig = $i * $this->a; //echo $heig."<br/>"; $this->L1[$i] = array($i, $heig, self::countResL1($heig)); $i++; } return true; } function countL2() { $c = $this->a; $i = 0; while ( $i <= $c) { $this->L2[$i] = array($i, self::countResL2($i)); $i++; } return true; } function mod($x, $y) { return fmod($x, $y); } function countResL1($heig) { $number = pow($this->f, $heig); //echo $number."<br>"; return self::mod( $number, $this->n); } function countResL2($heig) { $number = $this->b * (pow($this->f, $heig)); //echo $number."<br>"; return self::mod( $number, $this->n); } function searchRes() { $c = count($this->L1)-1; $i = 0; while ( $i<= $c) { $ser = $this->L1[$i][2]; $res = self::searchValueInL2($ser); if($res !== false) { return $this->findStr = $i."_".$res; } $i++; } return false; } function searchValueInL2($value) { $c = count($this->L2)-1; $i = 0; while ( $i <= $c) { if($this->L2[$i][1] == $value) { return $i; } $i++; } return false; } function finalResult() { $elem = split("_", $this->findStr); $first = self::mod($this->b, $this->n); $heig = $this->L1[$elem[0]][1] - $this->L2[$elem[1]][0]; $this->result = ceil(self:: mod ( pow($this->f,$heig), $first)) ; } function showRiv() { $elem = split("_", $this->findStr); $f_h = ($this->L2[$elem[1]][0] != 1) ? $this->L2[$elem[1]][0] : ' '; echo " ".$this->b." * ".$this->f. "<sup><small>".$f_h."</small></sup> = ". $this->f."<sup><small>".$this->L1[$elem[0]][1]. "</small></sup> mod ". $this->n; } function getResult() { return $this->result; } } $alg = new BigAndSmallStep(2, 11, 13); if ( ($alg->countL1() != false) && ($alg->countL2() !=false )){ $alg->searchRes(); $alg->finalResult(); $alg->showRiv(); echo "<br/> Result x = ".$alg->getResult(); } else echo "Ошибочка =("; ?>
Output for 7.0.0 - 7.1.0
Fatal error: Uncaught Error: Call to undefined function split() in /in/nVoe1:111 Stack trace: #0 /in/nVoe1(136): BigAndSmallStep->finalResult() #1 {main} thrown in /in/nVoe1 on line 111
Process exited with code 255.
Output for 5.4.0 - 5.4.45, hhvm-3.10.0 - 3.12.0
11 * 2<sup><small> </small></sup> = 2<sup><small>8</small></sup> mod 13<br/> Result x = 7
Output for 5.5.0 - 5.6.28
Deprecated: Function split() is deprecated in /in/nVoe1 on line 111 Deprecated: Function split() is deprecated in /in/nVoe1 on line 120 11 * 2<sup><small> </small></sup> = 2<sup><small>8</small></sup> mod 13<br/> Result x = 7
Output for 4.3.0 - 5.3.29
<? class BigAndSmallStep { public $f; public $b; public $n; public $a; public $L1 = array(); public $L2 = array(); public $findStr; public $result; public function __construct ($f, $b, $n) { $this->f = intval($f); $this->b = intval($b); $this->n = intval($n); $this->a = self::countA($this->n); } function countA($n) { return ceil(sqrt($n)); } function countL1() { $c = $this->a-1; $i = 0; while ( $i <= $c) { $heig = $i * $this->a; //echo $heig."<br/>"; $this->L1[$i] = array($i, $heig, self::countResL1($heig)); $i++; } return true; } function countL2() { $c = $this->a; $i = 0; while ( $i <= $c) { $this->L2[$i] = array($i, self::countResL2($i)); $i++; } return true; } function mod($x, $y) { return fmod($x, $y); } function countResL1($heig) { $number = pow($this->f, $heig); //echo $number."<br>"; return self::mod( $number, $this->n); } function countResL2($heig) { $number = $this->b * (pow($this->f, $heig)); //echo $number."<br>"; return self::mod( $number, $this->n); } function searchRes() { $c = count($this->L1)-1; $i = 0; while ( $i<= $c) { $ser = $this->L1[$i][2]; $res = self::searchValueInL2($ser); if($res !== false) { return $this->findStr = $i."_".$res; } $i++; } return false; } function searchValueInL2($value) { $c = count($this->L2)-1; $i = 0; while ( $i <= $c) { if($this->L2[$i][1] == $value) { return $i; } $i++; } return false; } function finalResult() { $elem = split("_", $this->findStr); $first = self::mod($this->b, $this->n); $heig = $this->L1[$elem[0]][1] - $this->L2[$elem[1]][0]; $this->result = ceil(self:: mod ( pow($this->f,$heig), $first)) ; } function showRiv() { $elem = split("_", $this->findStr); $f_h = ($this->L2[$elem[1]][0] != 1) ? $this->L2[$elem[1]][0] : ' '; echo " ".$this->b." * ".$this->f. "<sup><small>".$f_h."</small></sup> = ". $this->f."<sup><small>".$this->L1[$elem[0]][1]. "</small></sup> mod ". $this->n; } function getResult() { return $this->result; } } $alg = new BigAndSmallStep(2, 11, 13); if ( ($alg->countL1() != false) && ($alg->countL2() !=false )){ $alg->searchRes(); $alg->finalResult(); $alg->showRiv(); echo "<br/> Result x = ".$alg->getResult(); } else echo "Ошибочка =("; ?>