Taxicab Numbers
A taxicab number is a positive integer that can be expressed as the sum of two positive cubes in more than one way.1
Implement the function
val taxicab : int -> int
so that taxicab n is the number of ways n can be expressed as
the sum of two positive cubes. The behavior of the function is
undefined if n is not positive.
Examples
let _ = assert (taxicab 2 = 1) let _ = assert (taxicab 5 = 0) let _ = assert (taxicab 1729 = 2) (* 1729 = 1^3 + 12^3 = 3^3 + 9^3 *) let _ = assert (taxicab 4104 = 2) (* 4104 = 2^3 + 16^3 = 9^3 + 15^3 *)
Footnotes:
1
This is slightly different from the usual definition.