mirror of
https://bitbucket.org/Mattrixwv/octavefunctions.git
synced 2026-02-03 19:52:31 -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?
|
%What is the value of the first triangle number to have over five hundred divisors?
|
||||||
|
|
||||||
%Setup your variables
|
%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
|
number = 0; %To hold the current triangle number
|
||||||
found = false; %To tell when the answer has been found
|
found = false; %To tell when the answer has been found
|
||||||
numDivisors = 0;
|
numDivisors = 0;
|
||||||
@@ -14,18 +14,18 @@ maxCounter = 0;
|
|||||||
startTime = clock();
|
startTime = clock();
|
||||||
while(~found)
|
while(~found)
|
||||||
%Get your next triangle number
|
%Get your next triangle number
|
||||||
number = sym(sum([1:counter]))
|
number = sym(sum([1:counter]));
|
||||||
|
|
||||||
%See if it has 500 divisors
|
%See if it has 500 divisors
|
||||||
numDivisors = size(divisors(number))(2)
|
numDivisors = size(divisors(number))(2);
|
||||||
if(numDivisors > maxDivisors)
|
if(numDivisors > maxDivisors)
|
||||||
maxDivisors = numDivisors
|
maxDivisors = numDivisors;
|
||||||
maxCounter = counter
|
maxCounter = counter;
|
||||||
end
|
end
|
||||||
if(numDivisors > 500)
|
if(numDivisors > 500)
|
||||||
found = true;
|
found = true;
|
||||||
else
|
else
|
||||||
counter = counter + 1
|
counter = counter + 1;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
endTime = clock();
|
endTime = clock();
|
||||||
|
|||||||
Reference in New Issue
Block a user