Updated to start from the beginning and rehide variables

This commit is contained in:
2018-09-26 23:50:59 -04:00
parent 3a748680b1
commit f2823c36dc

View File

@@ -3,7 +3,7 @@
%What is the value of the first triangle number to have over five hundred divisors?
%Setup your variables
counter = 3500; %To hold the current number you have counted up to
counter = 1; %To hold the current number you have counted up to
number = 0; %To hold the current triangle number
found = false; %To tell when the answer has been found
numDivisors = 0;
@@ -14,18 +14,18 @@ maxCounter = 0;
startTime = clock();
while(~found)
%Get your next triangle number
number = sym(sum([1:counter]))
number = sym(sum([1:counter]));
%See if it has 500 divisors
numDivisors = size(divisors(number))(2)
numDivisors = size(divisors(number))(2);
if(numDivisors > maxDivisors)
maxDivisors = numDivisors
maxCounter = counter
maxDivisors = numDivisors;
maxCounter = counter;
end
if(numDivisors > 500)
found = true;
else
counter = counter + 1
counter = counter + 1;
end
end
endTime = clock();