Problem 23: Non-abundant sums

I do not understand the reason why this is not working. I am testing until 100 manually and it is operating correctly.

let sumOfProperDivisors = 0;
let number = 0;
let arrayOfAbundantNumbers = [];
let sumOfDeficientNumbers = 0;
let sumOfAbundantNumbers = 0;
let sumOfNumbersWhichCannotBeAdded = 0;
let arrayOfNumbersWhichCannotBeAdded = [];
let limit = 100;
      
      while(number<limit){

			for(let i = 1;i<number;i++){
				
					if(number%i==0){
				    
				           sumOfProperDivisors = sumOfProperDivisors + i; 
												              	
				   		          };
					  };

			if(sumOfProperDivisors>number){
							         arrayOfAbundantNumbers.push(number);
							         sumOfAbundantNumbers=sumOfAbundantNumbers + number; 
							}else{
			                         sumOfDeficientNumbers = sumOfDeficientNumbers + number;
							};

			for(let i = 0;i<arrayOfAbundantNumbers.length;i++){
			        		for(let j = 0;j<arrayOfAbundantNumbers.length;j++){
			        				if(number==arrayOfAbundantNumbers[i] + arrayOfAbundantNumbers[j]){
			                                    arrayOfNumbersWhichCannotBeAdded.push(number);
			                                    sumOfNumbersWhichCannotBeAdded = sumOfNumbersWhichCannotBeAdded + number; 
			                                    //console.log("we cannot add this number to sumOfDeficientNumbers ");

									};	
									break;
                            };
			        };

			    number = number + 1; 
                sumOfProperDivisors = 0;

			};

			total = sumOfDeficientNumbers + sumOfAbundantNumbers  - sumOfNumbersWhichCannotBeAdded;

That nesting makes me suspicious of you timing out

1 Like

No, the nest is not causing me problems. I am getting less than 2 seconds with 28123. The problem is that I am getting a high sum of integers and I do not understand the reason why.

2 seconds is pretty long. That’s a problem.

1 Like

Let me solve that first, then I will come back with a question. Thanks!