Last active
March 24, 2022 15:22
-
-
Save sp301415/64812b2fc882422b066712a5169144b2 to your computer and use it in GitHub Desktop.
Now you can be top 5% at mathematics, according to that stupid puzzle
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
from sage.all import * | |
""" | |
Solve a/(b+c) + b/(a+c) + c/(a+b) = N | |
Reference: https://ami.uni-eszterhazy.hu/uploads/papers/finalpdf/AMI_43_from29to41.pdf | |
""" | |
N = 6 # Fun fact: There is no solution when N is odd! | |
print(f"[+] Finding solution for: a/(b+c) + b/(a+c) + c/(a+b) = {N}") | |
# Build an elliptic curve and mapping. | |
E = EllipticCurve([0, 4 * N**2 + 12 * N - 3, 0, 32 * (N + 3), 0]) | |
T = [E(t) for t in E.torsion_subgroup()] | |
print(f"[+] Elliptic curve: {latex(E)}") | |
def point_to_sol(x, y): | |
a = 8 * (N + 3) - x + y | |
b = 8 * (N + 3) - x - y | |
c = 2 * (-4 * (N + 3) - x * (N + 2)) | |
if a < 0: | |
a, b, c = -a, -b, -c | |
g = GCD(GCD(a, b), c) | |
return a // g, b // g, c // g | |
# Get one integral point of E. | |
P = E.integral_points() | |
# Generator must be inside the "egg". | |
for p in P: | |
if p[0] < 0: | |
break | |
print(f"[+] Found integral point: {p}") | |
cnt = 1 | |
q = p | |
# Iterate until we find positive solution. | |
is_found = False | |
while True: | |
print(f"[*] Trying {cnt} * P") | |
for qq in [q] + [q + t for t in T]: | |
a, b, c = point_to_sol(qq[0], qq[1]) | |
if (a > 0) and (b > 0) and (c > 0): | |
print("[+] Found a, b, c!") | |
is_found = True | |
break | |
if is_found: | |
break | |
q += p | |
cnt += 1 | |
print(f"[+] a = {a}") | |
print(f"[+] b = {b}") | |
print(f"[+] c = {c}") | |
# Check! | |
assert a / (b + c) + b / (c + a) + c / (b + a) == N |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment