Skip to content

Instantly share code, notes, and snippets.

@megahomyak
Last active February 6, 2022 21:12
Show Gist options
  • Save megahomyak/b020d5d0e7bbbc174cc12bd57664619e to your computer and use it in GitHub Desktop.
Save megahomyak/b020d5d0e7bbbc174cc12bd57664619e to your computer and use it in GitHub Desktop.
Finds coefficients for quadratic equations using bruteforce. Use only when you cannot find them by yourself
known_points = [(-2, -1), (-3, 1), (1, 5)]
step = 0.25
max_value = 3
a = -max_value
while a <= max_value:
b = -max_value
while b <= max_value:
c = -max_value
while c <= max_value:
if all(
y == (a * (x ** 2) + b * x + c)
for x, y in known_points
):
print(f"{a=}, {b=}, {c=}")
exit()
c += step
b += step
a += step
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment