Port forward tree iterator from python to rust.

This commit is contained in:
Tom Alexander
2026-06-27 19:31:59 -04:00
parent fba8203cda
commit 1b09c77492
15 changed files with 862 additions and 25 deletions

View File

@@ -0,0 +1,39 @@
#!/usr/bin/env python
#
from math import log10
def main():
for x, y, z, num_nodes in sorted(list(get_matches(90, 90)), key=lambda val: val[3]):
if num_nodes < 1000000:
print(f"{x}**{y} == {y}**{z} == {num_nodes}")
def get_matches(max_x: int, max_y: int):
for x in range(2, max_x):
for y in range(2, max_y):
diff, y_exp = check(x, y)
if diff == 0:
yield (x, y, y_exp, x**y)
def check(x: int, y: int):
num_nodes = x**y
# y**z = x**y
# zlogy = ylogx
# z = ylogx/logy
# flipped:
exp_for_y = y * log10(x) / log10(y)
# Round the exp for y to be a plain integer
exp_for_y = round(exp_for_y)
flipped_num_nodes = y**exp_for_y
# compare the num nodes after rounding to find a good fit with integers.
diff = abs(num_nodes - flipped_num_nodes)
return diff, exp_for_y
if __name__ == "__main__":
main()