% Collatz Conjecture Test with Sequence Display
% ---------------------------------------------
% This program tests the Collatz conjecture for all integers
% from 2 to 100 and displays the sequence of each number
% until it converges to 1.

clc; clear; close all;

maxNum = 100; % upper limit
disp(['Testing Collatz conjecture from 2 to ', num2str(maxNum), '...']);
disp('-------------------------------------------------------------');

for n = 2:maxNum
    x = n;
    sequence = x; % store the sequence
    
    % Generate the Collatz sequence
    
    while x ~= 1
        if mod(x, 2) == 0
            x = x / 2;
        else
            x = 3 * x + 1;
        end
        sequence(end+1) = x; % append next value
    end
    
    % Display the sequence
    fprintf('n = %d: ', n);
    fprintf('%d ', sequence);
    fprintf('\n');
end

disp('-------------------------------------------------------------');
disp('Collatz conjecture holds for all numbers from 2 to 100.');



