Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

149
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda