# Taxi-cab numbers

I got a look one huge Java code suggestion from one newbie high jacker of old thread, so I had to write this code.

http://oeis.org/A001235 (for values with minimum 2 ways, first difference is 87539319 with three ways. You can of course change the if part of the print to get the same list exactly)

``````""" find taxi-cab numbers which can be expressed as sum of cubes exactly two ways """
from collections import defaultdict
n = 1000000
qubes = [y**3 for y in range(int(n**(1/3))+1)]
ramanujan = defaultdict(int)
for ind, a in enumerate(qubes):
for b in qubes[ind:]:
if a + b > n: break
ramanujan[a+b] += 1

print(sorted(n for n in ramanujan if ramanujan[n] == 2))``````
TrustyTony 888

In Python2 you must use for example 1./3 at line 4 or do

``from __future__ import division``
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.