% LAB_08: 2016-07-08
% EXCEL EA-1
clear % Delete all variables
clc % Clear the Command Window
close all % Close any open figures
format compact % Remove blank lines in Command Window output
%% Introduction to while loops (1)
clear
clc
% Here is another way of running a loop a certain number of times
% This could also be done with a for loop
c = 1; % Initialize a "counter" variable
while c <= 5
disp('c is equal to:');
c
c = c + 1; % Increment the counter
end
%% Collatz Conjecture
% Write a program to generate a "Collatz sequence" according to this rule:
%
% Start with a positive integer n
% if n is even, divide it by 2
% if n is odd, multiply by three and add 1
% Continue this process until n reaches 1
% For an extra challenge, alter your code so that it counts the length of
% the sequence for a given value of n. Then use a loop to find the length
% of the sequences for each positive integer from 1 to 1000.
% Start with an initial value of n
n = 6; % just an example - you could use any positive integer you want
%...
%% Fibonacci numbers
% The Fibonacci sequence is obtained by the following rule:
% Add the previous two Fibonacci numbers to get the next Fibonacci number
% Start with the sequence 1, 1. The sequence continues , 2, 3, 5, 8, 13,
% Write a program to print all the Fibonacci numbers less than 4 million
%...
%% Advanced: Bubble sort algorithm
% More info about Bubble Sort can be found at
% en.wikipedia.org/wiki/Bubble_sort
% Start with an out-of-order list
list = [3, 4, 2, 7, 6, 5, 8, 1];
% If you would like to generate a random out-of-order list, use:
% [list, i] = sort(rand(1, 10))
% the variable "list" now has your out-of-order list
% Write your code here:
% ...