![]() |
|
Welcome to the Computer Webmaster Gaming Console Graphics Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| |||||||
| Pear Pear programming, this is a very complex subject as with using pear with php can be a difficult task for some, so lets talk pear. |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 | ||
| msaraujo Thu May 17 01:22:39 2007 UTC Modified files: /pear/Text_CAPTCHA_Numeral Numeral.php Log: added exponentiation and factorial methods, as well some tweaks in constructor's logic http://cvs.php.net/viewvc.cgi/pear/T...&diff_format=u Index: pear/Text_CAPTCHA_Numeral/Numeral.php diff -u pear/Text_CAPTCHA_Numeral/Numeral.php:1.5 pear/Text_CAPTCHA_Numeral/Numeral.php:1.6 --- pear/Text_CAPTCHA_Numeral/Numeral.php:1.5 Sun Apr 29 19:52:03 2007 +++ pear/Text_CAPTCHA_Numeral/Numeral.php Thu May 17 01:22:39 2007 @@ -1,5 +1,6 @@ <?php require_once 'Text/CAPTCHA/Numeral/interfaces/NumeralInterface.php'; + // {{{ Class Text_CAPTCHA_Numeral // +----------------------------------------------------------------------+ // | PHP version 5 | @@ -194,6 +195,8 @@ $this->operators[] = '*'; $this->operators[] = '%'; $this->operators[] = '/'; + $this->operators[] = '^'; + $this->operators[] = '!'; $this->maxValue = '100'; break; case self::TEXT_CAPTCHA_NUMERAL_COMPLEXITY_ELEMENTARY: @@ -332,14 +335,21 @@ * @access private * @see $this->operation */ - private function setOperation() + private function setOperation($type = null) { - $this->operation = $this->getFirstNumber() . ' ' . - $this->operator . ' ' . - $this->getSecondNumber(); - return $this; + if (strcmp(strtoupper($type),"F") === 0) { + $this->operation = $this->getFirstNumber() . ' ' . $this->operator; + + } + else { + $this->operation = $this->getFirstNumber() . ' ' . + $this->operator . ' ' . + $this->getSecondNumber(); + } + return $this; } // }}} + // {{{ private function generateNumber /** * Generate a number @@ -412,13 +422,18 @@ $secondNumber = $this->getSecondNumber(); } - if ($secondNumber === 0) { + if ($secondNumber == 0) { ++$secondNumber; $this->doDivision($firstNumber, $secondNumber); return; } - if ($firstNumber % $secondNumber !== 0) { + if ($firstNumber == 0) { + $this->doDivision(++$firstNumber,$secondNumber); + return; + } + + if ($firstNumber % $secondNumber != 0) { --$firstNumber; --$secondNumber; @@ -479,6 +494,49 @@ $this->setAnswer($answer); } // }}} + + // {{{ + /** + * Does an exponentiation on the values + * + * This function executes an exponentiation + * + * @access private + * @see $this->setOperation, $this->getFirstNumber, $this->getSecondNumber, $this->setAnswer() + */ + private function doExponentiation() + { + $this->setOperation() + ->setAnswer(pow($this->getFirstNumber(),$this->getSecondNumber())); + } + // }}} + + // {{{ + /** + * Enter description here... + * + */ + private function doFactorial() + { + $this->setOperation('F') + ->setAnswer(self::calculateFactorial($this->getFirstNumber())); + } + + // }}} + + // {{{ + /** + * Enter description here... + * + * @param integer $n + * @return integer + */ + private static function calculateFactorial($n) + { + return $n <= 1 ? 1 : $n * self::calculateFactorial($n - 1); + } + // }}} + // {{{ private function generateOperation /** * Generate the operation @@ -511,6 +569,16 @@ case '/': $this->doDivision(); break; + case '^': + $this->minValue = 10; + $this->doExponentiation(); + break; + case '!': + $this->minValue = 1; + $this->maxValue = 10; + $this->generateFirstNumber(); + $this->doFactorial(); + break; default: $this->doAdd(); break; @@ -579,4 +647,4 @@ // }}} } // }}} -?> +?> \ No newline at end of file | |||
| Featured Websites | ||||
|
![]() |
| Tags: cvs, numeralphp, pear, text_captcha_numeral |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| cvs: pear-core / package-PEAR.xml package2.xml /PEAR/PackageFile/Generator v2.php | Greg Beaver | Pear | 0 | 05-20-2007 7:42 PM |
| cvs: pear-core / package-PEAR.xml package2.xml /PEAR Installer.php /PEAR/PackageFile v1.php /PEAR/PackageFile/v2 Validator.php | Greg Beaver | Pear | 0 | 05-20-2007 7:42 PM |
| karma on Text_CAPTCHA_Numeral | Marcelo Araujo | Pear | 2 | 05-20-2007 7:41 PM |
| karma on Text_CAPTCHA_Numeral | Marcelo Araujo | Pear | 0 | 05-20-2007 7:41 PM |
| [ANNOUNCEMENT] Text_CAPTCHA_Numeral-1.2.0 (stable) Released. | PEAR Announce | Pear | 0 | 05-20-2007 6:34 PM |
| Featured Websites | ||||
|