Skip to content

Instantly share code, notes, and snippets.

@seonatic
Created June 29, 2018 14:04
Show Gist options
  • Save seonatic/bdac6385b04373b24e811493b0201e64 to your computer and use it in GitHub Desktop.
Save seonatic/bdac6385b04373b24e811493b0201e64 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/gokimad
<!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>
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