From f2823c36dc2046cdd120e4c6f1a5ee33138ee5d4 Mon Sep 17 00:00:00 2001 From: Mattrixwv Date: Wed, 26 Sep 2018 23:50:59 -0400 Subject: [PATCH] Updated to start from the beginning and rehide variables --- ProjectEuler/Problem12.m | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ProjectEuler/Problem12.m b/ProjectEuler/Problem12.m index 0ab08b7..978a3d7 100644 --- a/ProjectEuler/Problem12.m +++ b/ProjectEuler/Problem12.m @@ -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();