mirror of
https://bitbucket.org/Mattrixwv/octavefunctions.git
synced 2025-12-06 18:53:57 -05:00
Added code to cleanup the variables at the end of the script
This commit is contained in:
@@ -22,4 +22,9 @@ end
|
|||||||
%When done this way it removes the possibility of duplicate numbers
|
%When done this way it removes the possibility of duplicate numbers
|
||||||
|
|
||||||
fullSum = sum(numbers);
|
fullSum = sum(numbers);
|
||||||
fullSum
|
ans = fullSum
|
||||||
|
|
||||||
|
%Cleanup your variables
|
||||||
|
clear fullSum;
|
||||||
|
clear numbers;
|
||||||
|
clear counter;
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
fib = [1, 1, 2]; %Holds the Fibonacci numbers
|
fib = [1, 1, 2]; %Holds the Fibonacci numbers
|
||||||
currentFib = fib(end) + fib(end - 1); %The current Fibonacci number to be tested
|
currentFib = fib(end) + fib(end - 1); %The current Fibonacci number to be tested
|
||||||
evenFib = [2]; %A subset of the even Fibonacci numbers
|
evenFib = [2]; %A subset of the even Fibonacci numbers
|
||||||
finalSum = 0;
|
|
||||||
|
|
||||||
while(currentFib < 4000000)
|
while(currentFib < 4000000)
|
||||||
%Add the number to the list
|
%Add the number to the list
|
||||||
@@ -20,5 +19,9 @@ while(currentFib < 4000000)
|
|||||||
currentFib = fib(end) + fib(end - 1);
|
currentFib = fib(end) + fib(end - 1);
|
||||||
end
|
end
|
||||||
|
|
||||||
finalSum = sum(evenFib);
|
sum(evenFib)
|
||||||
finalSum
|
|
||||||
|
%Cleanup your variables
|
||||||
|
clear fib;
|
||||||
|
clear currentFib;
|
||||||
|
clear evenFib;
|
||||||
|
|||||||
@@ -36,12 +36,13 @@ end
|
|||||||
%When the last number is not divisible by a prime number it must be a prime number
|
%When the last number is not divisible by a prime number it must be a prime number
|
||||||
factors(end + 1) = tempNum;
|
factors(end + 1) = tempNum;
|
||||||
|
|
||||||
%Remove the variables
|
%Print the answer
|
||||||
|
max(factors)
|
||||||
|
|
||||||
|
%Cleanup your variables
|
||||||
clear counter;
|
clear counter;
|
||||||
clear tempNum;
|
clear tempNum;
|
||||||
clear answer;
|
clear answer;
|
||||||
clear number;
|
clear number;
|
||||||
clear primeNums;
|
clear primeNums;
|
||||||
|
clear factors;
|
||||||
%Print the answer
|
|
||||||
max(factors)
|
|
||||||
|
|||||||
@@ -28,12 +28,14 @@ while(outerCounter < size(numbers)(2))
|
|||||||
++outerCounter; %Increment
|
++outerCounter; %Increment
|
||||||
end
|
end
|
||||||
|
|
||||||
|
max(palindromes)
|
||||||
|
|
||||||
|
%Cleanup your variables
|
||||||
clear outerCounter;
|
clear outerCounter;
|
||||||
clear innerCounter;
|
clear innerCounter;
|
||||||
clear answer;
|
clear answer;
|
||||||
clear numbers;
|
clear numbers;
|
||||||
|
clear palindromes;
|
||||||
max(palindromes)
|
|
||||||
|
|
||||||
%This way is slow. I would like to find a faster way
|
%This way is slow. I would like to find a faster way
|
||||||
%{
|
%{
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
%What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
|
%What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
|
||||||
|
|
||||||
%Create your variables
|
%Create your variables
|
||||||
value = 0; %The value that is evenly divisible
|
|
||||||
nums = [1:20];
|
nums = [1:20];
|
||||||
factors = [1]; %The factors that are already in the number
|
factors = [1]; %The factors that are already in the number
|
||||||
list = []; %For a temperary list of the factors of the current number
|
list = []; %For a temperary list of the factors of the current number
|
||||||
@@ -33,13 +32,12 @@ while(counter <= size(nums)(2))
|
|||||||
++counter;
|
++counter;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
prod(factors)
|
||||||
|
|
||||||
%Cleanup your variables
|
%Cleanup your variables
|
||||||
clear counter;
|
clear counter;
|
||||||
clear factorCnt;
|
clear factorCnt;
|
||||||
clear listCnt;
|
clear listCnt;
|
||||||
clear list;
|
clear list;
|
||||||
clear nums;
|
clear nums;
|
||||||
clear ans; %Appears whenever you use increment
|
clear factors;
|
||||||
|
|
||||||
value = prod(factors);
|
|
||||||
value
|
|
||||||
|
|||||||
Reference in New Issue
Block a user