Last active
December 23, 2015 18:59
-
-
Save dsposito/6679585 to your computer and use it in GitHub Desktop.
Revisions
-
dsposito renamed this gist
Nov 26, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
dsposito created this gist
Sep 24, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,59 @@ <?php /** * Contains methods for interacting with numbers. * * @author Daniel Sposito <daniel.g.sposito@gmail.com> */ class Number { /** * Builds an array contain $count number of prime numbers. * * @param int $count The total number of prime numbers to return. * * @return array */ public static function primes($count) { $number = 1; $total_primes = 0; while ($total_primes < $count) { if (self::isPrime($number)) { $primes[] = $number; $total_primes++; } $number++; } return $primes; } /** * Determines whether or not a number is prime. * * @param int $number The number to check. * * @return boolean */ public static function isPrime($number) { if ($number == 1) { return false; } for ($i = 2; $i <= $number; $i++) { if ($number != $i && $number % $i == 0) { return false; } } return true; } } $count = 100; echo "First $count Prime Numbers: " . implode(', ', Number::primes($count));