# Not a lesson but! need help!

NOT A LESSON BUT! NEED HELP!

i am trying to produce taxicab numbers. sometimes, this does not work because this code uses too much memory. Any tips on how to make this utilize less space?

``````

var sums = [];
var way1 = [];
var ways2 =[];
var ways3 = [];
function cab(a, n) {
var y = 0;

for(var x = 1;x < a; x++){
for(var o =1; o < a;o++){
sums.push((Math.pow(x,3) + Math.pow(o,3)));

}

}

sums.toString();
sums.sort();
parseInt(sums);
for(var i = 0; i < sums.length; i++){
y = 0;
for(var p  = 0; p < sums.length;p++){
if(sums[p] === sums[i] && sums[i-1] !== sums[i]){
y++;
}

}

if(y/2 < 2 && sums[i-1] !== sums[i] ){
way1.push(sums[i]);

}else if(y/2 === 2){
ways2.push(sums[i]);

}else if(y/2 === 3){
ways3.push(sums[i]);
}

}

way1.toString();
way1.sort(function(a,b){return a - b;});
parseInt(way1);

ways2.toString();
ways2.sort(function(a,b){return a - b;});
parseInt(ways2);

ways3.toString();
ways3.sort(function(a,b){return a - b;});
parseInt(ways3);

if(n === 1){
return "[" + way1[0] + "]";
}else if(n === 2){
return "[" + ways2[0] + "]";
}else{
return ways3[0];
}

};

cab(200,2);
``````

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