Merge pull request #90 from Samadmemon991/master

Added neon number checker
This commit is contained in:
Brandon Johnson 2022-10-12 01:08:16 -06:00 committed by GitHub
commit adaff8d4d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 0 deletions

View File

@ -22,6 +22,7 @@
* [Fastexponentiation](./Maths/FastExponentiation.php)
* [Fibonacci](./Maths/Fibonacci.php)
* [Fibonacci2](./Maths/Fibonacci2.php)
* [Neon Number](./Maths/NeonNumber.php)
* [Perfectsquare](./Maths/PerfectSquare.php)
* Projecteuler
* [Problem1](./Maths/ProjectEuler/Problem1.php)

12
Maths/NeonNumber.php Normal file
View File

@ -0,0 +1,12 @@
<?php
function isNumberNeon($input)
{
$inputSquare = $input * $input;
$inputArr = array_map('intval', str_split($inputSquare));
$sumOfSquareDigits =0;
foreach ($inputArr as $digit) {
$sumOfSquareDigits +=$digit;
}
return $sumOfSquareDigits ==$input;
}
?>

View File

@ -15,6 +15,7 @@ require_once __DIR__ . '/../../Maths/Factorial.php';
require_once __DIR__ . '/../../Maths/FastExponentiation.php';
require_once __DIR__ . '/../../Maths/Fibonacci.php';
require_once __DIR__ . '/../../Maths/Fibonacci2.php';
require_once __DIR__ . '/../../Maths/NeonNumber.php';
require_once __DIR__ . '/../../Maths/PerfectSquare.php';
class MathsTest extends TestCase
@ -98,6 +99,13 @@ public function testIsNumberPalindromic()
assertEquals([0, 1, 1, 2, 3, 5, 8, 13, 21, 34], fibonacciWithBinetFormula(10));
}
public function testNeonNumber()
{
assertTrue(isNumberNeon(1));
assertFalse(isNumberNeon(43));
assertFalse(isNumberNeon(123));
assertTrue(isNumberNeon(9));
}
public function testFibonacciGenerator()
{
assertEquals([0, 1, 1, 2, 3], iterator_to_array(loop(5, fib())));