https://github.com/paparascal2020/code-kata-integers-recreate-one
Codewars Kata: Find all integers between m and n (m and n integers with 1 <= m <= n) such that the sum of their squared divisors is itself a square.
https://github.com/paparascal2020/code-kata-integers-recreate-one
Last synced: 29 days ago
JSON representation
Codewars Kata: Find all integers between m and n (m and n integers with 1 <= m <= n) such that the sum of their squared divisors is itself a square.
- Host: GitHub
- URL: https://github.com/paparascal2020/code-kata-integers-recreate-one
- Owner: PapaRascal2020
- Created: 2022-06-18T11:52:01.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-06-18T15:44:18.000Z (almost 4 years ago)
- Last Synced: 2025-01-02T18:21:08.957Z (over 1 year ago)
- Language: PHP
- Size: 1.06 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# code-kata-integers-recreate-one
Codewars Kata: Find all integers between m and n (m and n integers with 1 <= m <= n) such that the sum of their squared divisors is itself a square.
# Task
Find all integers between m and n (m and n integers with 1 <= m <= n) such that the sum of their squared divisors is itself a square.
We will return an array of subarrays or of tuples (in C an array of Pair) or a string. The subarrays (or tuples or Pairs) will have two elements: first the number the squared divisors of which is a square and then the sum of the squared divisors.
# For Codewars
This is what I had to put in, the code for my PHP Unit project was slightly different.
function listSquared($m, $n) : array
{
$divisors = [];
for ($i = $m; $i <= $n; $i++) {
$squaredNumber = getDivisorSquared($i);
if (isSquareNumber($squaredNumber)) {
$divisors[] = [$i, $squaredNumber];
}
}
return $divisors;
}
function isSquareNumber($number) : bool
{
return sqrt($number) == floor(sqrt($number));
}
function getDivisorSquared($number) : int
{
$result = 0;
for($i = 1; $i <= round(sqrt($number)); $i++){
if($number % $i === 0){
$result += $i ** 2;
$ii = $number / $i;
if ($i !== $ii) {
$result += $ii ** 2;
}
}
}
return $result;
}