Created
October 28, 2015 20:09
-
-
Save trys/46079677c8932c253e98 to your computer and use it in GitHub Desktop.
Problem Twenty One
This file contains hidden or 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
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