Created
October 4, 2021 17:11
-
-
Save VityaSchel/0bd0b4e22b30e8fb9ee14aec2e0c6aed to your computer and use it in GitHub Desktop.
Калькулятор корней через дискриминант и теорему, обратную теореме Виета
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function guesser(k1, k2) { | |
for(let i = -Math.abs(k1); i < Math.abs(k1); i++){ | |
for(let j = -Math.abs(k2); j < Math.abs(k2); j++){ | |
if(i+j === k1 && i*j === k2){ | |
return [i, j] | |
} | |
} | |
} | |
console.log('не удалось отгадать') | |
} | |
function discr(a, b, c){ | |
const d = b*b - 4*a*c | |
return [(-b+Math.sqrt(d))/(2*a),(-b-Math.sqrt(d))/(2*a)] | |
} | |
console.log(guesser(3, 2)) // [2, 1] | |
console.log(discr(5, 2, -7)) // [1, -1.4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment