
A   taxicab number   (the definition that is being used here)   is a positive integer that can be expressed as the sum of two positive cubes in more than one way.



The first taxicab number is   1729,   which is:

 13   +   123       and also
 93   +   103.


Taxicab numbers are also known as:

   taxi numbers
   taxi-cab numbers
   taxi cab numbers
   Hardy-Ramanujan numbers


Task

 Compute and display the lowest 25 taxicab numbers (in numeric order, and in a human-readable format).
 For each of the taxicab numbers, show the number as well as it's constituent cubes.


Extra credit
 Show the 2,000th taxicab number, and a half dozen more


See also

 A001235: taxicab numbers on The On-Line Encyclopedia of Integer Sequences.
 Hardy-Ramanujan Number on MathWorld.
 taxicab number on MathWorld.
 taxicab number on Wikipedia   (includes the story on how taxi-cab numbers came to be called).


 
(import (scheme base)
        (scheme write)
        (srfi 1)        ; lists
        (srfi 69)       ; hash tables
        (srfi 132))     ; sorting
 
(define *max-n* 1500) ; let's go up to here, maximum for x and y
(define *numbers* (make-hash-table eqv?)) ; hash table for total -> list of list of pairs
 
(define (retrieve key) (hash-table-ref/default *numbers* key '()))
 
;; add all combinations to the hash table
(do ((i 1 (+ i 1)))
  ((= i *max-n*) )
  (do ((j (+ 1 i) (+ j 1)))
    ((= j *max-n*) )
    (let ((n (+ (* i i i) (* j j j))))
      (hash-table-set! *numbers* n 
                       (cons (list i j) (retrieve n))))))
 
(define (display-number i key)
  (display (+ 1 i)) (display ": ") 
  (display key) (display " -> ")
  (display (retrieve key)) (newline))
 
(let ((sorted-keys (list-sort < 
                              (filter (lambda (key) (> (length (retrieve key)) 1))
                                      (hash-table-keys *numbers*)))))
  ;; first 25 
  (for-each (lambda (i) (display-number i (list-ref sorted-keys i)))
            (iota 25))
  ;; 2000-2006
  (for-each (lambda (i) (display-number i (list-ref sorted-keys i)))
            (iota 7 1999))
  )
 