Skip to content

Instantly share code, notes, and snippets.

@Dobby233Liu
Last active November 30, 2024 06:20
Show Gist options
  • Save Dobby233Liu/c829d7ef0296a87a087035bc52d8b681 to your computer and use it in GitHub Desktop.
Save Dobby233Liu/c829d7ef0296a87a087035bc52d8b681 to your computer and use it in GitHub Desktop.
Binary search solver in HTA???
<!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>
@Dobby233Liu
Copy link
Author

its janky because i am literally replicating a logic flowchart in a textbook with this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment