function[output] = simulation(n, k)
% n = number of runs
% k = number of apples
results = 1:n; % here I will save results of n trials
for i = 1:n
    results(i) = apples(k);
end

subplot(1,2,1)
    histogram(results, 'facecolor', 'r', 'binwidth', 1)
    % set binwidth to one so we can see how many runs ended with the same result
    title('results of apple simulation')
    xlabel('number of kids')
    ylabel('frequencies')
    
subplot(1,2,2)
    n_apples = k;
    % here we will save how many apples is left currently
    eaten_apples = 0;
    % here we will save number of eaten apples
    i = 1;
    while eaten_apples <= k
        eaten = randi([0, 1], 1);
        n_apples(i + 1) = n_apples(i) - eaten;
        eaten_apples = eaten_apples + eaten;
        i = i + 1;
    stairs(n_apples, 'r')
    ylim([0, k + 1])
    title('trajectory of one run')
    xlabel('number of kids')
    ylabel('number of apples')
    end
end