SHARE
TWEET

JavaScript Node.js Answer Code

a guest May 2nd, 2016 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function splitDigits(i) {
  2.   return [parseInt(String(i).substring(0,1)), parseInt(String(i).substring(1,2)), parseInt(String(i).substring(2,3)), parseInt(String(i).substring(3,4))]
  3. }
  4. function isPrime(value) {
  5.   for(var i = 2; i < value; i++) {
  6.     if(value % i === 0) {
  7.        return false;
  8.     }
  9.   }
  10.   return value > 1;
  11. }
  12. for (var i = 7000; i < 10000; i++) {
  13.   var combo = splitDigits(i)
  14.   var a = combo[0]
  15.   var b = combo[1]
  16.   var c = combo[2]
  17.   var d = combo[3]
  18.   var secondAnswer = (a * b * c * d) + (a + b + c + d)
  19.   if (a + b + c + d > (a * b) - (c * d) && a > 6 && isPrime(i) && (secondAnswer % a === 0 && secondAnswer % c === 0 && secondAnswer % b !== 0 && secondAnswer % d !== 0)) {
  20.     console.log(i)
  21.   }
  22. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top