-
-
Save MCMi460/d379a9d31173b7ce3b12c9a2d0a144e1 to your computer and use it in GitHub Desktop.
Pythagorean Tripes
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
# Now supports TI-84 Plus CE Python Calculators | |
import math | |
def brute_search(recursion_depth:int = 200): | |
nums = list(range(recursion_depth)) | |
i = 1 | |
while i < len(nums): | |
a = nums[i] | |
for b in range(a, recursion_depth): | |
c = math.sqrt(a**2 + b**2) # Pythagorean theorem | |
if c % 1 == 0: | |
if b in nums[i:]: | |
nums.remove(b) | |
yield (a, b, int(c)) | |
i += 1 | |
def formula_search(recursion_depth:int = 10): # Not as refined - recursion_depth is much more intensive | |
for m in range(1, recursion_depth): | |
for n in range(m + 1, recursion_depth): | |
a = -1 * (m**2 - n**2) | |
b = 2 * m * n | |
c = m**2 + n**2 | |
yield (a, b, c) | |
input('Brute Search\n[PRESS ENTER TO CONTINUE]') | |
for triple in brute_search(): | |
print(triple) | |
input('Formula Search\n[PRESS ENTER TO CONTINUE]') | |
for triple in formula_search(): | |
print(triple) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment