Created
June 29, 2018 14:04
-
-
Save seonatic/bdac6385b04373b24e811493b0201e64 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/gokimad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
function listSquared (m, n) { | |
var matches = []; | |
for (var i = m; i <= n; ++i) { | |
var sum = getDivisors(i).reduce((sum, n) => sum + n * n, 0); | |
var ok = Number.isInteger(Math.sqrt(sum)); | |
if (ok) { | |
matches.push([i, sum]); | |
} | |
} | |
return matches; | |
} | |
function getDivisors (n) { | |
var divisors = []; | |
for (var i = 1; i <= n / 2; ++i) { | |
if (n % i) { //n % i is the opposite of n % i ==0 | |
continue; | |
} | |
divisors.push(i); | |
} | |
return divisors.concat([n]); | |
} | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">function listSquared (m, n) { | |
var matches = []; | |
for (var i = m; i <= n; ++i) { | |
var sum = getDivisors(i).reduce((sum, n) => sum + n * n, 0); | |
var ok = Number.isInteger(Math.sqrt(sum)); | |
if (ok) { | |
matches.push([i, sum]); | |
} | |
} | |
return matches; | |
} | |
function getDivisors (n) { | |
var divisors = []; | |
for (var i = 1; i <= n / 2; ++i) { | |
if (n % i) { //n % i is the opposite of n % i ==0 | |
continue; | |
} | |
divisors.push(i); | |
} | |
return divisors.concat([n]); | |
}</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function listSquared (m, n) { | |
var matches = []; | |
for (var i = m; i <= n; ++i) { | |
var sum = getDivisors(i).reduce((sum, n) => sum + n * n, 0); | |
var ok = Number.isInteger(Math.sqrt(sum)); | |
if (ok) { | |
matches.push([i, sum]); | |
} | |
} | |
return matches; | |
} | |
function getDivisors (n) { | |
var divisors = []; | |
for (var i = 1; i <= n / 2; ++i) { | |
if (n % i) { //n % i is the opposite of n % i ==0 | |
continue; | |
} | |
divisors.push(i); | |
} | |
return divisors.concat([n]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment