##Negative and Positve, Sum of 2 Cubes "Taxi Cab Numbers" ##
##Problem high to low. Ie. 6^3 - 5^3 = 91, 3^3 + 4^3 = 91
##Ramanujan was working on a Generator for -(1) Odd in his
##Notebooks. See "A Study of the Crank Function in
##Ramanujans Lost Notebook" by 'Manjil.P.Saikia' Page 14. (2.22)
##Good application for Mellin Quantum Transform, Quantum Computing
##Answers lack integer 5. Ie Accelerated Continued Fraction
##See Also 'Gaussâ€™s Composition Law' in "Basics of binary quadratic
##forms and Gauss composition" A.Granville 2004.
##Cut and Paste into Python Idle. Warren B
def Neg_Cubic_Sum_Taxi_cab_numbers(n):
Selected_num = 0
Neg_Num_Cubed = 0
v_ans = {}
cache1 = {}
i = 0
s_hail = 0
while Selected_num < n:
cache1[i] = i*i*i
for j in range(i):
s_hail = cache1[j] + cache1[i]
if(Neg_Num_Cubed > 0):
s_hail = cache1[i] - cache1[j]
##s_hail = cache1[i] - cache1[j] #j is < i
if s_hail in v_ans:#
Selected_num += 1#Selection num
Neg_Num_Cubed = 1
if(s_hail != (cache1[i] - cache1[j])):
yield(s_hail, (j, i), v_ans[s_hail])#
if(s_hail == (cache1[i] - cache1[j])):
yield(s_hail, (j, i),"- Cube =", v_ans[s_hail])#
v_ans[s_hail] = (j,i)#
i += 1
if(s_hail > 130000):
break
def m_neg(n):
for x in Neg_Cubic_Sum_Taxi_cab_numbers(n):
print(x)
>>> m_neg(3)
(1729, (1, 12), (9, 10))
(1512, (6, 12), '- Cube =', (8, 10))
(1216, (8, 12), '- Cube =', (6, 10))
(728, (10, 12), '- Cube =', (6, 8))
##Taxi Cab Numbers
##Code Author 'pchandra',from "Stack Overflow"
##This solution (in python) generates the first n taxi cab number
##in a bottom up approach. The time complexity is m^2 where m is
##the highest number it will go to generate the n numbers.
def generate_taxi_cab_numbers(n):
generated_number = 0
v = {}
c = {}
i = 0
s = 0
while generated_number < n:
c[i] = i*i*i
for j in range(i):
s = c[j] + c[i]
if s in v:
generated_number = generated_number + 1
yield (s, (j, i), v[s])
v[s] = (j,i)
i = i + 1
if(s > 30000):
break
def m(n):
for x in generate_taxi_cab_numbers(n):
print(x)