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

151
Visualizações
The time required to destroy a building in the browser game is calculated incorrectly
// Number of rockets launched per second.
const rocketSpeed = 1;

// The amount of damage dealt by rocket.
const attackDamage = 60;

// The amount of hit points of the building.
const buildingHitPoints = 1000;

// The number of rockets required to destroy the building.
const numberOfRockets = Math.ceil(buildingHitPoints / attackDamage);

// The time it takes to destroy the building.
const requiredTime = numberOfRockets * rocketSpeed;

If the rocketSpeed is more than one second, then I get the correct value.

For example: const requiredTime = 17 * 1;

But if you specify a rocketSpeed less than 1 second, then the value is incorrect:

For example: const requiredTime = 17 * 0.625; // 10.625

0.625 is the number of rockets fired per second. That is, 1 rocket will be launched in about ~ 1.2 seconds.

I've tried different options by type: const requiredTime = 17 + (17 - 37.5%); (37.5% because: 1000 - 625 = 375. 375 is 37.5% of 1000), but it doesn't work.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Number of rockets launched per second is better thought of as a frequency than a "speed".

Frequency f is f = 1/T where time is T, so T = 1/f

Maybe rename rocketSpeed to rocketFrequency and make a new variable timeBetweenRockets with
const timeBetweenRockets = 1 / rocketFrequency.

Then the last line of code will be more selfexplaining

const requiredTime = numberOfRockets * timeBetweenRockets

about 4 years ago · Juan Pablo Isaza Relatório

0

You have the calculation the wrong way round. If you try values greater than 1 then you'll see it takes longer: 1 rocket per second (r/s) results in 17 seconds. 2 r/s results in 34 seconds and 0.5 r/s gives 10.625 seconds.

const calculate = rocketSpeed => {

  // The amount of damage dealt by rocket.
  const attackDamage = 60;

  // The amount of hit points of the building.
  const buildingHitPoints = 1000;

  // The number of rockets required to destroy the building.
  const numberOfRockets = Math.ceil(buildingHitPoints / attackDamage);

  // The time it takes to destroy the building.
  const requiredTime = numberOfRockets * rocketSpeed;
  
  return requiredTime;
}
 
console.log(`Time for 1 rocket/s: ${calculate(1)}`);
console.log(`Time for 2 rocket/s: ${calculate(2)}`);
console.log(`Time for 0.625 rocket/s: ${calculate(0.625)}`);

If you instead divide numberOfRockets by rocketSpeed you'll get the right answers.

const calculate2 = rocketSpeed => {

  // The amount of damage dealt by rocket.
  const attackDamage = 60;

  // The amount of hit points of the building.
  const buildingHitPoints = 1000;

  // The number of rockets required to destroy the building.
  const numberOfRockets = Math.ceil(buildingHitPoints / attackDamage);

  // The time it takes to destroy the building.
  const requiredTime = numberOfRockets / rocketSpeed;
  
  return requiredTime;
}

console.log(`Time for 1 rocket/s: ${calculate2(1)}`);
console.log(`Time for 2 rocket/s: ${calculate2(2)}`);
console.log(`Time for 0.625 rocket/s: ${calculate2(0.625)}`);

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