tower_of_powers_inverse.sf 882 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/ruby
  2. # Daniel "Trizen" Șuteu
  3. # Date: 05 June 2020
  4. # https://github.com/trizen
  5. # Find a real solution to x^x^x^...^x = n for a tower of k powers.
  6. func tower_of_powers_inverse(n, k) { # solution for x^x^...^x = n
  7. bsearch_inverse(n, {|v|
  8. k.of(v).reduce{|a,b|
  9. b**a
  10. } <~> n
  11. })
  12. }
  13. func nested_powers_inverse(n, k) { # solution for ((...)^x)^x = n
  14. bsearch_inverse(n, {|v|
  15. k.of(v).reduce{|a,b|
  16. a**b
  17. } <~> n
  18. })
  19. }
  20. # Find x such that x^(x^(x^x)) = 2
  21. # x = 1.4466014324298641745973339875976614806873210422...
  22. with (tower_of_powers_inverse(2, 4)) {|x|
  23. say x
  24. assert(x**(x**(x**x)) =~= 2)
  25. }
  26. # Find x such that ((x^x)^x)^x = 2
  27. # x = 1.3367097349494955658483777999091512580783714292...
  28. # Equivalently: x^(x^3) = 2
  29. with (nested_powers_inverse(2, 4)) {|x|
  30. say x
  31. assert(((x**x)**x)**x =~= 2)
  32. }