Compare commits
2 Commits
4dd1683e1a
...
master
Author | SHA1 | Date | |
---|---|---|---|
29cfd35fe9 | |||
f622721892 |
@ -1 +0,0 @@
|
|||||||
vendor/
|
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +1,4 @@
|
|||||||
output/
|
output/
|
||||||
.*.cache/
|
.*.cache/
|
||||||
|
vendor/
|
||||||
|
tools/
|
4
.phive/phars.xml
Normal file
4
.phive/phars.xml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<phive xmlns="https://phar.io/phive">
|
||||||
|
<phar name="phpunit" version="^12.2.2" installed="12.2.2" location="./tools/phpunit" copy="false"/>
|
||||||
|
</phive>
|
9
solutions/Generic/MultiTable/desc.yml
Normal file
9
solutions/Generic/MultiTable/desc.yml
Normal file
@ -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
|
@ -1,7 +1,7 @@
|
|||||||
title: Sieve of Eratosthenes
|
title: Sieve of Eratosthenes
|
||||||
url: http://en.wikipedia.org/wiki/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
|
solution: Do i need to say more
|
||||||
|
|
||||||
solutions:
|
solutions:
|
||||||
|
@ -8,12 +8,12 @@ class Numerical
|
|||||||
{
|
{
|
||||||
public static function isPandigital(int $input): bool
|
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
|
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
|
private static function isDigitsPresent(int $input, array $count): bool
|
||||||
|
@ -12,12 +12,20 @@ use CodingTests\Prime;
|
|||||||
#[CoversClass(Prime::class)]
|
#[CoversClass(Prime::class)]
|
||||||
final class PrimeTest extends \PHPUnit\Framework\TestCase
|
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++) {
|
for ($test = -100; $test <= 100; $test++) {
|
||||||
$ret = Prime::isPrime($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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user