473,320 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Ramanujan & Python


A bit of fun:

Ramanujan, an Indian mathematician, was once visited in the hospital
by G. H. Hardy, a prominant English mathematician. Hardy remarked
that he had taken taxi number 1729, and Ramanujan quickly replied
that 1729 is remarkable, as it is the smallest integer that can be
represented in two ways by the sum of two cubes: 1729 = 1**3 + 12**3
= 9**3 + 10**3 [1].

Spectacular, no?

The inspired reader checks this with a quick Python program:
L = range(1,21)
sums = [x**3+y**3 for x in L for y in L]
histo = [sums.count(i) for i in range(max(sums)+1)]
histo.index(4)

1729

Explanation:
20**3 is 8000, so our search extends only up to 8000.
sums contains x**3+y**3 values for each x in L for each y in L.
(note that 1**3 + 12**3 and 12**3 and 1**3 are counted twice in sums).
histo counts how many times each value appears in sums.

The point is that Python is great for mathematical experiments.

This particular program is inefficient on the histo= line, so if you
want to try other cases (such as smallest integer that can be
represented in two ways by the sum of two fourths), you'll need to
optimize.

[1]. http://scienceworld.wolfram.com/biog...Ramanujan.html

This document is in the public domain.

- Connelly
Jul 18 '05 #1
2 3061
ba*****@engr.orst.edu wrote:
Spectacular, no?


Not really.

I'm might sound a bit of off topic here I but I consider both of
these as 'cheapo' tricks that only sound good on paper (and to
reporters): 'Look Ma the man can compute the sum of two cubes
in a flash'

1**3 is 1, all he needed to know is that 12**3 is 1728
Similarly knowing that 10**3 is 1000 is trivial, all he
needed to know is that 9**3 is 729.

Just as with squared values whenever one works with cubes
they will tune very quickly in and start recognize the first
20 or so by heart in a matter of minutes...

Istvan.

Jul 18 '05 #2
Istvan Albert <ia*****@mailblocks.com> writes:
1**3 is 1, all he needed to know is that 12**3 is 1728
Similarly knowing that 10**3 is 1000 is trivial, all he
needed to know is that 9**3 is 729.

Just as with squared values whenever one works with cubes
they will tune very quickly in and start recognize the first
20 or so by heart in a matter of minutes...


There's another part to the question. Is there a smaller number than
1729, that's also the sum of two cubes in two distinct ways? Ramanujan
could answer that second question immediately. Can you?
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Edward K. Ream | last post by:
Am I reading pep 277 correctly? On Windows NT/XP, should filenames always be converted to Unicode using the mbcs encoding? For example, myFile = unicode(__file__, "mbcs", "strict") This...
0
by: Brano Zarnovican | last post by:
Hi ! I'd like to init curses and still have working Python interactive command line. I found that you can replace stdin/stdout/stderr like this: #!/usr/bin/python -i import curses import...
4
by: webdev | last post by:
lo all, some of the questions i'll ask below have most certainly been discussed already, i just hope someone's kind enough to answer them again to help me out.. so i started a python 2.3...
7
by: Kirt | last post by:
i have walked a directory and have written the foll xml document. one of the folder had "&" character so i replaced it by "&amp;" #------------------test1.xml <Directory> <dirname>C:\Documents and...
7
by: John Nagle | last post by:
I've been parsing existing HTML with BeautifulSoup, and occasionally hit content which has something like "Design & Advertising", that is, an "&" instead of an "&amp;". Is there some way I can get...
3
by: Pappy | last post by:
SHORT VERSION: Python File B changes sys.stdout to a file so all 'prints' are written to the file. Python file A launches python file B with os.popen("./B 2>&^1 >dev/null &"). Python B's output...
0
by: newbie73 | last post by:
Going through the tutorial on http://swig.org, I created the example files (pasted below). After generating the _wrap file, I tried compiling (using mingw32) and received a lot of undefined...
4
by: emre esirik(hacettepe computer science and enginee | last post by:
I couldnt find how to I can find ramanujan numbers with c code
3
by: bsagert | last post by:
Some web feeds use decimal character entities that seem to confuse Python (or me). For example, the string "doesn't" may be coded as "doesn’t" which should produce a right leaning apostrophe....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.