|
|
|
|
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);
?> | | |
|
| Diffusion-Limited Aggregation visualization Categories : PHP, Graphics, Algorithms, Math. | | | Reverse a given number Categories : PHP, Beginner Guides, 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 | | | 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. | | | Latitude-Longitude to Miles Categories : PHP, Utilities, Math. | | | Math operations on big numbers Categories : PHP, Math. | | | what salt do I have to feed the crypt function with to make it work like the htpasswd command of apache? Categories : Algorithms, PHP, Authentication | | | The Porter Word Stemming Algorithm in PHP
Reduces words to their base stem for search engines and indexing Categories : Algorithms, PHP, Strings | | | Mail-lib provides a simple interface to the sendmail program. Note: you must actually have sendmail on your machine (sorry windows NT users). Categories : Algorithms, Email, PHP | | | A recursive function to traverse a multi-dimensional array where the
dimensions are not known Categories : Arrays, PHP, Algorithms | | | Dollar Serial Number Validator Categories : PHP, Security, Algorithms | | | A simple bubblesort that takes 2 arrays as argument.The first one is the actual data used for sorting, the second is data that will "tag along" with the first array, for instance a descriptive text about the data in the first array. Categories : Algorithms, Arrays, PHP, Complete Programs | | | Kasskooye($path) tell you the complete size of a folder
Categories : PHP, Algorithms, Utilities, Filesystem | | | How to validate an Israeli ID number. Categories : Ecommerce, PHP, Algorithms | |
|
|