clear;
mu = 4;
max_count = 400;
gain = 1;
ATTEN_CONST = 0.99;
max_moves = 30;
min_moves = 1;

for j=1:max_count
    z(j, 1) = 0.65;
        
    for i=1:max_count-1
        z(j, i+1) = mu*z(j, i)*(1-z(j, i));
    end
    
    for i=1:max_count
        z(j, i) = gain*z(j, i);
    end
    
    gain = gain * ATTEN_CONST;
    
end

curr_count = 1;
num_counts = zeros(max_count*max_count, 2);
for j=1:max_count
    prob_dist(1:100, j) = zeros(1:100, 1);
    num_moves(1:max_moves+1-min_moves,j) = zeros(1:max_moves+1-min_moves, 1);
    for i=1:max_count
        prob_dist(round(z(j, i)*99)+1, j) = prob_dist(round(z(j, i)*99)+1,j) + 1;
        move_dist = floor(z(j, i) * (max_moves - min_moves) + min_moves);       
        num_moves(floor(move_dist), j) = num_moves(floor(move_dist), j) + 1;
        num_counts(curr_count, 1) = j;
        num_counts(curr_count, 2) = move_dist;
        curr_count = curr_count + 1;
    end
    prob_dist(:, j) = prob_dist(:, j) / max_count - ones(100,1)/100000;
end

hist3(num_counts, [max_count, 30])