mirror of
https://bitbucket.org/Mattrixwv/octavefunctions.git
synced 2025-12-07 11:13:57 -05:00
Updated to start from the beginning and rehide variables
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user