Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

145
Vistas
How do I divide numbers from two arrays into a new one. I am trying to make a rational zeroes thereom calculator of sorts for fun

This is as far as I've gotten. I have factored the numbers successfully, but I just need to distribute and divide them into the pOverQ array.

var p = readInt("What is your p: ");
var q = readInt("What is your q: ");
var factorP = [];
var factorQ = [];
var pOverQ = [];
var num = 0;
    


function start(){
    factor(p, q);
    println(factorP);
    println(factorQ);
    p_Q(p, q);
    println(pOverQ);
}

function factor(p ,q){

    for(var i = 1; i <= p; i++) {
        
        if(p % i == 0){
             factorP.push(i);
        }
        if(q % i == 0){
            factorQ.push(i);
        }
    }
}

function p_Q(p, q){
    for(var i = 0; i < (factorP.length)*2; i++){
        pOverQ.push(factorP[i]/factorQ[i]);
    }
}

I hope you can help!!!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It looks like you are trying to build something like this: rational zeros theorem calculator

Here are a few steps towards it:

function factor(p){ // find all factors of a single number
  let res=[];
  for(let i=1;i<=p;i++) if(p%i == 0) res.push(i);
  return res;
}
function p_q(P,Q){ // combine P- and Q-arrays and find all distinct fractions
  const coll={}, qarr=factor(Q);
  factor(P).forEach(p=>qarr.forEach(q=>{
   let frac=reduce(p,q);
   coll[frac.join("/")]=frac
  }));
  return coll;
}
// https://stackoverflow.com/a/4652513/2610061
function reduce(num,den){ // reduce a given fraction
  // greatest common denominator:
  function gcd(a,b){return b ? gcd(b, a%b) : a;};
  const g = gcd(num,den);
  return [num/g, den/g];
}
const res=p_q(6,7);
console.log(Object.keys(res));  // show the fractions as text ...
console.log(Object.values(res).map(([n,d])=>n/d)); // ... and as values

As @jsN00b already mentioned, you will need to consider both, positive and negative values of the calculated fractions as possible solutions for your polynomium. But I 'll leave that bit to you.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda