diff --git a/.gitignore b/.gitignore index ccb638a..c33b761 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ output/ .*.cache/ -vendor/ \ No newline at end of file +vendor/ +tools/ \ No newline at end of file diff --git a/.phive/phars.xml b/.phive/phars.xml new file mode 100644 index 0000000..f21864c --- /dev/null +++ b/.phive/phars.xml @@ -0,0 +1,4 @@ + + + + diff --git a/solutions/Generic/MultiTable/desc.yml b/solutions/Generic/MultiTable/desc.yml new file mode 100644 index 0000000..8327cfd --- /dev/null +++ b/solutions/Generic/MultiTable/desc.yml @@ -0,0 +1,9 @@ +title: Multiplication table + + +desc: Building a multiplication table in C + +solutions: + solve.c: + desc: ANSI C solution (Tested with TCC) + language: c diff --git a/solutions/Generic/Seive/desc.yml b/solutions/Generic/Seive/desc.yml index 66efe5c..d2637d0 100644 --- a/solutions/Generic/Seive/desc.yml +++ b/solutions/Generic/Seive/desc.yml @@ -1,7 +1,7 @@ title: Sieve of Eratosthenes url: http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes -desc:Generate primes from 2 to 100 +desc: Generate primes from 2 to 100 solution: Do i need to say more solutions: diff --git a/src/Numerical.php b/src/Numerical.php index 6274710..8706fc8 100644 --- a/src/Numerical.php +++ b/src/Numerical.php @@ -8,12 +8,12 @@ class Numerical { public static function isPandigital(int $input): bool { - return self::isDigitsPresent($input, [49 => 1, 50 => 1, 51 => 1, 52 => 1, 53 => 1, 54 => 1, 55 => 1, 56 => 1, 57 => 1]); + return self::isDigitsPresent($input, [0x31 => 1, 0x32 => 1, 0x33 => 1, 0x34 => 1, 0x35 => 1, 0x36 => 1, 0x37 => 1, 0x38 => 1, 0x39 => 1]); } public static function isPandigitalWithZero(int $input): bool { - return self::isDigitsPresent($input, [48 => 0, 49 => 1, 50 => 1, 51 => 1, 52 => 1, 53 => 1, 54 => 1, 55 => 1, 56 => 1, 57 => 1]); + return self::isDigitsPresent($input, [0x30 => 1, 0x31 => 1, 0x32 => 1, 0x33 => 1, 0x34 => 1, 0x35 => 1, 0x36 => 1, 0x37 => 1, 0x38 => 1, 0x39 => 1]); } private static function isDigitsPresent(int $input, array $count): bool diff --git a/tests/PrimeTest.php b/tests/PrimeTest.php index 5fd270f..653dcab 100644 --- a/tests/PrimeTest.php +++ b/tests/PrimeTest.php @@ -12,12 +12,20 @@ use CodingTests\Prime; #[CoversClass(Prime::class)] final class PrimeTest extends \PHPUnit\Framework\TestCase { - public function isPandigital(): void + static $primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]; + public function testisPrime(): void { - $primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]; for ($test = -100; $test <= 100; $test++) { $ret = Prime::isPrime($test); - $this->assertEquals(in_array($test, $primes), $ret, "Testing $test"); + $this->assertEquals(in_array($test, self::$primes), $ret, "Testing $test"); + } + } + + public function testis_prime(): void + { + for ($test = -100; $test <= 100; $test++) { + $ret = Prime::isPrime($test); + $this->assertEquals(in_array($test, self::$primes), $ret, "Testing $test"); } } }