mirror of
https://github.com/TheAlgorithms/PHP.git
synced 2025-01-17 15:18:13 +01:00
Merge pull request #90 from Samadmemon991/master
Added neon number checker
This commit is contained in:
commit
adaff8d4d3
@ -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
12
Maths/NeonNumber.php
Normal 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;
|
||||
}
|
||||
?>
|
@ -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())));
|
||||
|
Loading…
x
Reference in New Issue
Block a user