Ramanujan & Python

Discussion in 'Python' started by barnesc@engr.orst.edu, Sep 6, 2004.

  1. Guest

    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/biography/Ramanujan.html

    This document is in the public domain.

    - Connelly
     
    , Sep 6, 2004
    #1
    1. Advertising

  2. 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.
     
    Istvan Albert, Sep 6, 2004
    #2
    1. Advertising

  3. Paul Rubin Guest

    Istvan Albert <> 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?
     
    Paul Rubin, Sep 6, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    770
  2. emre esirik(hacettepe com. sci. and eng.)

    do u know ramanujan numbers algorithm

    emre esirik(hacettepe com. sci. and eng.), Feb 27, 2008, in forum: Java
    Replies:
    16
    Views:
    4,576
    Prasannabhore
    Jan 8, 2014
  3. emre esirik(hacettepe computer science and enginee

    do u know ramanujan numbers algorithm

    emre esirik(hacettepe computer science and enginee, Feb 27, 2008, in forum: C Programming
    Replies:
    4
    Views:
    408
    Richard Heathfield
    Feb 27, 2008
  4. Paul Moore
    Replies:
    0
    Views:
    654
    Paul Moore
    Mar 1, 2008
  5. Martin v. Löwis
    Replies:
    0
    Views:
    691
    Martin v. Löwis
    Mar 1, 2008
Loading...

Share This Page