Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6645549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:18:04+00:00 2026-05-26T00:18:04+00:00

I remember once going to see [Srinivasa Ramanujan] when he was ill at Putney.

  • 0

I remember once going to see
[Srinivasa Ramanujan] when he was ill
at Putney. I had ridden in taxi cab
number 1729 and remarked that the
number seemed to me rather a dull one,
and that I hoped it was not an
unfavorable omen. “No,” he replied,
“it is a very interesting number; it
is the smallest number expressible as
the sum of two cubes in two different
ways.” [G. H. Hardy as told in “1729
(number)”
]

In “Math Wrath” Joseph Tartakovsky says about this feat, “So what?
Give me two minutes and my calculator watch, and I’ll do the same
without exerting any little gray cells.” I don’t know how
Mr. Tartakovsky would accomplish that proof on a calculator watch, but
the following is my scheme function that enumerates numbers starting
at 1 and stops when it finds a number that is expressable in two
seperate ways by summing the cubes of two positive numbers. And it
indeeds returns 1729.

There are two areas where I would appreciate suggestions for
improvement. One area is, being new to scheme, style and idiom. The other area is around the calculations. Sisc
does not return exact numbers for roots, even when they could be. For
example (expt 27 1/3) yields 2.9999999999999996. But I do get exact
retults when cubing an exact number, (expt 3 3) yields 27. My
solution was to get the exact floor of a cube root and then test
against the cube of the floor and the cube of the floor plus one,
counting as a match if either match. This solution seems messy and hard to reason about. Is there a more straightforward way?

; Find the Hardy-Ramanujan number, which is the smallest positive
; integer that is the sum of the cubes of two positivie integers in
; two seperate ways.
(define (hardy-ramanujan-number)
  (let ((how-many-sum-of-2-positive-cubes
          ; while i^3 + 1 < n/1
          ;     tmp := exact_floor(cube-root(n - i^3))
          ;     if n = i^3 + tmp^3 or n = i^3 + (tmp + 1) ^3 then count := count + 1
          ; return count
          (lambda (n)
            (let ((cube (lambda (n) (expt n 3)))
                  (cube-root (lambda (n) (inexact->exact (expt n 1/3)))))
              (let iter ((i 1) (count 0)) 
                (if (> (+ (expt i 3) 1) (/ n 2))
                    count
                    (let* ((cube-i (cube i))
                           (tmp (floor (cube-root (- n cube-i)))))
                      (iter (+ i 1)
                        (+ count
                          (if (or (= n (+ cube-i (cube tmp)))
                                  (= n (+ cube-i (cube (+ tmp 1)))))
                              1
                              0))))))))))
    (let iter ((n 1))
      (if (= (how-many-sum-of-2-positive-cubes n) 2)
          n
          (iter (+ 1 n))))))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:18:04+00:00Added an answer on May 26, 2026 at 12:18 am

    Your code looks mostly fine, I see a few very minor things to comment on:

    • There’s no need to define cube and cube-root at the innermost scope,

    • Using define for internal functions makes it look a little clearer,

    • This is related to the second part of your question: you’re using inexact->exact on a floating point number which can lead to large rationals (in the sense that you allocate a pair of two big integers) — it would be better to avoid this,

    • Doing that still doesn’t solve the extra test that you do — but that’s only because you’re not certain if you have the right number of if you missed by 1. Given that it should be close to an integer, you can just use round and then do one check, saving you one test.

    Fixing the above, and doing it in one function that returns the number when it’s found, and using some more “obvious” identifier names, I get this:

    (define (hardy-ramanujan-number n)
      (define (cube n) (expt n 3))
      (define (cube-root n) (inexact->exact (round (expt n 1/3))))
      (let iter ([i 1] [count 0])
        (if (> (+ (cube i) 1) (/ n 2))
          (hardy-ramanujan-number (+ n 1))
          (let* ([i^3   (cube i)]
                 [j^3   (cube (cube-root (- n i^3)))]
                 [count (if (= n (+ i^3 j^3)) (+ count 1) count)])
            (if (= count 2) n (iter (+ i 1) count))))))
    

    I’m running this on Racket, and it looks like it’s about 10 times faster (50ms vs 5ms).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I remember once i had temporary data used on a webpage. I used php
I remember reading once that .NET had a built in configSection handler that could
I remember once in school we had the task of programming a marquee text
I remember reading something once, but could not find it now while searching, if
I once encountered an operator ===. But I don remember what it was.. or
I once remember seeing an addon or something for VS2008. It was provided by
I can't remember the name of this, but I remember seeing this once. I
I remember once seeing a website, which deciphered complex C++ typedefs including function pointers
I remember having once seen a list of properties that could be set on
I remember I once seen a operator which is able to decompose a list

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.