|
|
|
|
Like this code?
Show the author your appreciation.
|
|
| |
This script uses Sieve of Erastothenes to find all the prime up to a number
| <?php
//Made by Chao Xu
//http://webdevlogs.com/
function esprime($limit){
$sqrtlimit = sqrt($limit);
$range = 0;
while($range<$limit){
$i .= '11';
$range+=2;
}
$n = 2;
while($n < $sqrtlimit){
if ($i[$n]){
$sqn = $n*$n;
$k = $sqn;
$i[$k]=0;
while($k<=$limit){
$k += $n;
$i[$k]=0;
}
}
++$n;
}
$n = 1;
while($n<$limit){
if($i[$n]) $primes[] = $n;
$n+=2;
}
if($limit>=2) $primes[0] = 2;
return $primes;
}
?> | |
It returns an array of all prime number below an the argument.
| <?php
esprime(6);
//return array(2,3,5);
?> | | |
|
| Library of math functions to expand the functionality of PHP3. Version 1.2.1 fixes a major problem with the gcd function.
Categories : Algorithms, PHP, Math. | | | Diffusion-Limited Aggregation visualization Categories : PHP, Graphics, Algorithms, Math. | | | Show the steps for converting a number from a given base to base 10. Shows the steps involved in converting a number from a given base to base 10. Categories : PHP, Math., Algorithms | | | How to judge if an integer is odd or is even in Php3? Categories : Math., PHP, Algorithms | | | abs -- Absolute value Categories : PHP, PHP Functions, Math. | | | Find the day of the week for any given year/month/day. Categories : PHP, Date Time, Data Validation, Algorithms, Beginner Guides | | | Dollar Serial Number Validator Categories : PHP, Security, Algorithms | | | Calculate Body Mass Index Categories : PHP, Algorithms, Regexps | | | A very simple and efficient split bar the B-Z bar , for mysql and php ...
Tired of obfuscated code try this one ...
Categories : PHP, Databases, MySQL, Algorithms | | | Paginating the mySQL data Categories : PHP, Algorithms, Databases, MySQL, HTML and PHP | | | Password Creator: This PHP code exmaple shows how to use bitwise operations on a single variable and using it as a flagged variable. The class generates passwords of a given length using specified characters and the flags. Categories : PHP, PHP Classes, Algorithms, Security | | | How to Generate a random 8 character string in php3? Categories : PHP, Algorithms | | | The Porter Word Stemming Algorithm in PHP
Reduces words to their base stem for search engines and indexing Categories : Algorithms, PHP, Strings | | | Arbitrary Precision Math using BCMATH routines Categories : PHP, Math., BC math | | | Check parameters validity. Paranoia was designed to check the validity of the parameters that a php page will receive after a form submission. It can be used to check the variables sent by POST or GET Categories : Algorithms, HTML and PHP, PHP, Variables | |
|
|
|