Problem 2369. Tribute to Ramanujan
The nth taxicab number, denoted as T(n), is defined as the smallest number that can be expressed as a sum of two positive algebraic cubes in n distinct ways (source: wikipedia).
Example:
T(1) = 2 = 1^3 + 1^3 T(2) = 1729 = 1^3 + 12^3 = 9^3 + 10^3
Return the value of n if the given number is a taxicab number. Return 0 if not. If the input is 1729, output would be 2, since 1729 is smallest number that can be expressed as a sum of two cubes in two (n=2) distinct ways.
Avoid look up table solution. Test suit might expand.
Solution Stats
Problem Comments
-
3 Comments
The solution must be a lookup table since the 6th taxicab number is already greater than 2^64. If anyone find an algorithm for this, DO NOT publish here, publish a scientific paper. Researchers published a paper just about the upper bounds for the 7th to12th number for instance.
The 6th taxicab number is not even a certainty apparently http://jucs.org/jucs_9_10/what_is_the_value/Calude_C_S.pdf
Still, there's a lot that can be done to show that this might be a general solution within MATLAB numeric bounds.
Test cases! E.g. 9 and 4104 would catch when someone isn't checking that they have the SMALLEST number for a given number of ways. (e.g. 9==2^3+1^3, and 4104 == 16^3 + 2^3 == 15^3 + 9^3 are the SECOND smallest numbers for 1 and 2 ways. Random cases could be defined for this one).
Outlaw shortcut functions like str2num. Outlaw the string "1729" and other ways to calculate it and other known taxicab numbers as other than the sum of two cubes two ways. [e.g. it turns out that 1729==prod(1:6:19)].
Solution Comments
Show commentsProblem Recent Solvers30
Suggested Problems
-
Find all elements less than 0 or greater than 10 and replace them with NaN
15527 Solvers
-
3661 Solvers
-
Determine if input is a perfect number
237 Solvers
-
841 Solvers
-
192 Solvers
More from this Author44
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!