logo CodeStepByStep logo

sumCubes

Language/Type: JavaScript algorithms interview

Write a function named sumCubes that accepts an integer n as a parameter and prints all unique combinations of values in the range [1, n] for which the following equality is true:

a3 + b3 = c3 + d3

For example, if n is 20, your function should print the following output:

1^3 + 12^3 = 9^3 + 10^3
2^3 + 16^3 = 9^3 + 15^3

The lines may appear in any order but must follow this exact format.

Function: Write a JavaScript function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.