legendary_question_six.sf 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/ruby
  2. # Daniel "Trizen" Șuteu
  3. # Date: 29 June 2019
  4. # https://github.com/trizen
  5. # Efficient method for computing non-trivial solutions to the legendary question six.
  6. # The Legend of Question Six - Numberphile
  7. # https://www.youtube.com/watch?v=Y30VF3cSIYQ
  8. # The Return of the Legend of Question Six - Numberphile
  9. # https://www.youtube.com/watch?v=L0Vj_7Y2-xY
  10. # Solutions for (a^2 + b^2) / (1 + ab) = 4, are given by A052530 = { 2, 8, 30, 112, 418, 1560, 5822, ... }.
  11. # Example:
  12. # ( 2^2 + 8^2) / ( 2*8 + 1) = 4
  13. # ( 8^2 + 30^2) / ( 8*30 + 1) = 4
  14. # ( 30^2 + 112^2) / ( 30*112 + 1) = 4
  15. # (112^2 + 418^2) / (112*418 + 1) = 4
  16. # Similar sequences provide solutions for other values:
  17. # For 3^2: A065100 = { 3, 27, 240, 2133, 18957, 168480, ... }
  18. # For 4^2: A154021 = { 4, 64, 1020, 16256, 259076, 4128960, ... }
  19. # For 5^2: A154022 = { 5, 125, 3120, 77875, 1943755, 48516000, ... }
  20. # For 6^2: A154023 = { 6, 216, 7770, 279504, 10054374, 361677960, ... }
  21. # More generally, let U(n,x) be the Chebyshev polynomials of the second kind, then (a^2 + b^2) / (1 + ab) = m^2, has solutions of the form:
  22. #
  23. # a = m * U(n, m^2 / 2)
  24. # b = m * U(n+1, m^2 / 2)
  25. #
  26. # for any given positive integer m.
  27. func lq6_solutions(m, how_many=5) {
  28. how_many.of {|n|
  29. [m * chebyshevU(n, m*m / 2), m * chebyshevU(n+1, m*m / 2)]
  30. }
  31. }
  32. for k in (2..10) {
  33. var S = lq6_solutions(k)
  34. say "(a^2 + b^2) / (1 + ab) = #{k}^2 has solutions: #{S}"
  35. }
  36. __END__
  37. (a^2 + b^2) / (1 + ab) = 2^2 has solutions: [[2, 8], [8, 30], [30, 112], [112, 418], [418, 1560]]
  38. (a^2 + b^2) / (1 + ab) = 3^2 has solutions: [[3, 27], [27, 240], [240, 2133], [2133, 18957], [18957, 168480]]
  39. (a^2 + b^2) / (1 + ab) = 4^2 has solutions: [[4, 64], [64, 1020], [1020, 16256], [16256, 259076], [259076, 4128960]]
  40. (a^2 + b^2) / (1 + ab) = 5^2 has solutions: [[5, 125], [125, 3120], [3120, 77875], [77875, 1943755], [1943755, 48516000]]
  41. (a^2 + b^2) / (1 + ab) = 6^2 has solutions: [[6, 216], [216, 7770], [7770, 279504], [279504, 10054374], [10054374, 361677960]]
  42. (a^2 + b^2) / (1 + ab) = 7^2 has solutions: [[7, 343], [343, 16800], [16800, 822857], [822857, 40303193], [40303193, 1974033600]]
  43. (a^2 + b^2) / (1 + ab) = 8^2 has solutions: [[8, 512], [512, 32760], [32760, 2096128], [2096128, 134119432], [134119432, 8581547520]]
  44. (a^2 + b^2) / (1 + ab) = 9^2 has solutions: [[9, 729], [729, 59040], [59040, 4781511], [4781511, 387243351], [387243351, 31361929920]]
  45. (a^2 + b^2) / (1 + ab) = 10^2 has solutions: [[10, 1000], [1000, 99990], [99990, 9998000], [9998000, 999700010], [999700010, 99960003000]]