TaciCab Solution

What is your hint or solution suggestion?
You can iterate through all the cubes increasing the amount of cubes as necessary and getting their sums with other cubes and keep track of the sums until you find 2 pairs which will be a taxi number.

function taxicabNumbers(n)
    let numCompleted=0;
    let cubesCount=1;
    let cubes=[1]
    let result=[]
        let sums={};
        for(let cube of cubes)
            for(let cube2 of cubes)
             let sum=cube+cube2;
             if(!(sum in sums ))sums[sum]=0;
             if(sums[sum]==4&&!result.includes(sum)) {result.push(sum);numCompleted++;break outer;}
    return result.sort((x,y)=>x-y);

Challenge: Taxicab numbers

Link to the challenge:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.