% Starter Code for Arithmetic Coding

rand('seed', 0);

numSymbols = 4; % The first symbol '1' to be used for stopping
p = [0.01; 0.1 + rand(numSymbols-1, 1)];
p = p/sum(p);

% Small Example
str1 = [randi([2 numSymbols], 5, 1); 1];
code = arithmeticEncode(p, str1); % Code
decodeStr = arithmeticDecode3(p, code);
display(code), 
display(str1),
display(decodeStr),

% Large Example
str1 = [randi([2 numSymbols], 30, 1); 1];
code = arithmeticEncode(p, str1); % Code
decodeStr = arithmeticDecode(p, code);
% display the following
code(10:15), 
[str1(10:15), decodeStr(10:15)],
% check if they are equal
all(decodeStr == str1),

