Last active
November 30, 2024 06:20
-
-
Save Dobby233Liu/c829d7ef0296a87a087035bc52d8b681 to your computer and use it in GitHub Desktop.
Binary search solver in HTA???
This file contains hidden or 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta http-equiv="X-UA-Compatible" content="IE=10"> | |
<title>solver</title> | |
</head> | |
<body onload="window.resizeTo(300, 300)"> | |
<script language="VBScript" type="text/vbscript"> | |
Function BoxedEval(func, x) | |
BoxedEval = Eval(func) | |
End Function | |
Function Solve(func, a, b, prec) | |
Dim c | |
Do While Abs(a - b) >= prec | |
c = (a + b) / 2 | |
If BoxedEval(func, a) * BoxedEval(func, c) < 0 Then | |
b = c | |
Else | |
a = c | |
If BoxedEval(func, c) = 0 Then | |
Exit Do | |
End If | |
End If | |
Loop | |
Solve = a | |
End Function | |
Function SolveAndDisplay() | |
Dim func, a, b, prec, result | |
func = document.getElementById("func").value | |
a = CDbl(document.getElementById("a").value) | |
b = CDbl(document.getElementById("b").value) | |
prec = CDbl(document.getElementById("prec").value) | |
result = Solve(func, a, b, prec) | |
document.getElementById("result").innerText = CStr(result) | |
SolveAndDisplay = False | |
End Function | |
</script> | |
<form action="#" onsubmit="return SolveAndDisplay()"> | |
<input type="text" id="func" placeholder="func"/> | |
<input type="text" id="a" placeholder="a"/> | |
<input type="text" id="b" placeholder="b"/> | |
<input type="text" id="prec" placeholder="prec"/> | |
<br/> | |
<input type="submit"/> | |
</form> | |
<span id="result"></span> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
its janky because i am literally replicating a logic flowchart in a textbook with this