Skip to content

Instantly share code, notes, and snippets.

@trys
Created October 28, 2015 20:09
Show Gist options
  • Save trys/46079677c8932c253e98 to your computer and use it in GitHub Desktop.
Save trys/46079677c8932c253e98 to your computer and use it in GitHub Desktop.
Problem Twenty One
var results = [],
a,
b;
function divisors( a ) {
var divisor = [];
for (var i = 1; i <= a / 2; i++) {
if ( a % i === 0 ) {
divisor.push( i );
}
}
if ( divisor.length > 1 ) {
return sum( divisor );
}
}
function sum( numbers ) {
var product = 0;
for (var i = 0; i < numbers.length; i++) {
product += numbers[i];
}
return product;
}
for (var i = 1; i <= 10000; i++) {
a = divisors( i );
if ( a ) {
b = divisors( a );
if ( b === i && b !== a && results.indexOf( i ) === -1 ) {
results.push( i, a );
}
}
}
document.write( sum( results ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment