samedi 25 septembre 2021

How to build an Equation with given him a result and values

I was trying to make some codes with javascript can change a "?" to correct operator some think like that 10 ? 20 ? 15 ? 3 ? 190 ? 10 ? 400 to 102015%319010*400 I was trying to make it like that But it just works when I give him a 2 value when I wanna give him 3 or more it does not work can anyone help me?

const OPMAP = {
    '*': (n1, n2) => n1 * n2,
    '/': (n1, n2) => n1 / n2,
    '+': (n1, n2) => n1 + n2,
    '-': (n1, n2) => n1 - n2,
    '%': (n1, n2) => n1 % n2
}

var op = ["+","/","-","*","%"]

let i = 1
let firstValue = 5, secondValue = 5

while(true){
  var operator = OPMAP[op[Math.floor(Math.random() * op.length)]]
  var x =  operator(firstValue, secondValue)
  if (x === i){
    console.log(operator)
    console.log(x)
    break
  }

} 



Aucun commentaire:

Enregistrer un commentaire