function[output] = apples(n_apples)
    n_kids = 0;
    % number of kids who came to the basket thus far
    apples_eaten = 0;
    % how many apples have been eaten thus far
    while apples_eaten <= n_apples
        n_kids = n_kids + 1;
        % in every loop we note that a kid has come to the basket
        took_apple = randi([0, 1], 1);
        % randomly generate 0 or 1, signifying if the kid took an apple
        apples_eaten = apples_eaten + took_apple;
    end
    output = n_kids;
end