Added code to cleanup the variables at the end of the script

This commit is contained in:
2018-09-26 11:17:37 -04:00
parent b63ca10669
commit 2468bd4f80
5 changed files with 24 additions and 15 deletions

View File

@@ -22,4 +22,9 @@ end
%When done this way it removes the possibility of duplicate numbers
fullSum = sum(numbers);
fullSum
ans = fullSum
%Cleanup your variables
clear fullSum;
clear numbers;
clear counter;

View File

@@ -6,7 +6,6 @@
fib = [1, 1, 2]; %Holds the Fibonacci numbers
currentFib = fib(end) + fib(end - 1); %The current Fibonacci number to be tested
evenFib = [2]; %A subset of the even Fibonacci numbers
finalSum = 0;
while(currentFib < 4000000)
%Add the number to the list
@@ -20,5 +19,9 @@ while(currentFib < 4000000)
currentFib = fib(end) + fib(end - 1);
end
finalSum = sum(evenFib);
finalSum
sum(evenFib)
%Cleanup your variables
clear fib;
clear currentFib;
clear evenFib;

View File

@@ -36,12 +36,13 @@ end
%When the last number is not divisible by a prime number it must be a prime number
factors(end + 1) = tempNum;
%Remove the variables
%Print the answer
max(factors)
%Cleanup your variables
clear counter;
clear tempNum;
clear answer;
clear number;
clear primeNums;
%Print the answer
max(factors)
clear factors;

View File

@@ -28,12 +28,14 @@ while(outerCounter < size(numbers)(2))
++outerCounter; %Increment
end
max(palindromes)
%Cleanup your variables
clear outerCounter;
clear innerCounter;
clear answer;
clear numbers;
max(palindromes)
clear palindromes;
%This way is slow. I would like to find a faster way
%{

View File

@@ -3,7 +3,6 @@
%What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
%Create your variables
value = 0; %The value that is evenly divisible
nums = [1:20];
factors = [1]; %The factors that are already in the number
list = []; %For a temperary list of the factors of the current number
@@ -33,13 +32,12 @@ while(counter <= size(nums)(2))
++counter;
end
prod(factors)
%Cleanup your variables
clear counter;
clear factorCnt;
clear listCnt;
clear list;
clear nums;
clear ans; %Appears whenever you use increment
value = prod(factors);
value
clear factors;