Created
September 1, 2017 21:06
-
-
Save durgaswaroop/8417d55a4e13013217606cc1c67f45a0 to your computer and use it in GitHub Desktop.
Python code to solve x**x**x = 10
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
# Written to calculate value of x such that x**x**x = 10 | |
# Corresponding Quora answer: https://www.quora.com/If-x-x-x-10-what-is-x/answer/DurgaSwaroop-Perla | |
factor = 100000000 | |
def direction(a, b): | |
if abs(a - b) < (a / factor): | |
return 0 | |
elif a - b < 0: | |
return -1 | |
elif a - b > 0: | |
return 1 | |
x = 1 | |
target = 10 | |
while True: | |
# print(x) | |
judgement = direction(x ** x ** x, target) | |
if judgement == 0: | |
print(x, x ** x ** x) | |
break | |
elif judgement == -1: | |
x = x + x / factor | |
else: | |
x = x - x / factor | |
# Final output: 1.9235840382154854 10.000000099999989 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment