SHARE
TWEET

Untitled

a guest Jan 18th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.   Distinct primes factors
  3.   Problem 47
  4.   The first two consecutive numbers to have two distinct prime factors are:
  5.  
  6.   14 = 2 × 7
  7.   15 = 3 × 5
  8.  
  9.   The first three consecutive numbers to have three distinct prime factors are:
  10.  
  11.   644 = 2² × 7 × 23
  12.   645 = 3 × 5 × 43
  13.   646 = 2 × 17 × 19.
  14.  
  15.   Find the first four consecutive integers to have four distinct prime factors
  16.   each. What is the first of these numbers?
  17. */  
  18. const fp = require('lodash/fp');
  19. const object = require('lodash/fp/object');
  20. const extend = require('lodash/fp/extend');
  21. const isPrime = require('is-prime-number');
  22.  
  23. const consec4 = x => fp.range(x,x+4);
  24.  
  25. function genFactors(n){
  26.  
  27.   let i = 2;
  28.   let t = n;
  29.   let f = [];
  30.  
  31.   while(t>1){
  32.     if (isPrime(i)){
  33.       if (!(t%i)){
  34.         f.push(i); t=t/i;
  35.       }
  36.       else {
  37.         i +=1;
  38.       }
  39.     }
  40.     else {
  41.       i+=1;
  42.     }
  43.   }
  44.  
  45.   return f;
  46. }
  47.  
  48. function compute(){
  49.  
  50.   let n = 134000, found = false;
  51.  
  52.   while(!found && n<1e6){
  53.     console.log('finding...')
  54.     found = fp.all(x=>fp.uniq(genFactors(x)).length===4)(consec4(n));
  55.     if (found){
  56.       console.log('found', n);
  57.       return n;
  58.     }
  59.     n += 1;
  60.   }
  61.  
  62.   return 0;
  63.  
  64. }
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