Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Distinct primes factors
- Problem 47
- The first two consecutive numbers to have two distinct prime factors are:
- 14 = 2 × 7
- 15 = 3 × 5
- The first three consecutive numbers to have three distinct prime factors are:
- 644 = 2² × 7 × 23
- 645 = 3 × 5 × 43
- 646 = 2 × 17 × 19.
- Find the first four consecutive integers to have four distinct prime factors
- each. What is the first of these numbers?
- */
- const fp = require('lodash/fp');
- const object = require('lodash/fp/object');
- const extend = require('lodash/fp/extend');
- const isPrime = require('is-prime-number');
- const consec4 = x => fp.range(x,x+4);
- function genFactors(n){
- let i = 2;
- let t = n;
- let f = [];
- while(t>1){
- if (isPrime(i)){
- if (!(t%i)){
- f.push(i); t=t/i;
- }
- else {
- i +=1;
- }
- }
- else {
- i+=1;
- }
- }
- return f;
- }
- function compute(){
- let n = 134000, found = false;
- while(!found && n<1e6){
- console.log('finding...')
- found = fp.all(x=>fp.uniq(genFactors(x)).length===4)(consec4(n));
- if (found){
- console.log('found', n);
- return n;
- }
- n += 1;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment