Predicting Peak Peeping

Predicting Peak Peeping
Photo by davide ragusa / Unsplash
using Distributions

function simtree(color_dist, x)
    color_time = rand(color_dist)
    fall_time = rand(DiscreteUniform(color_time+1, length(x)))
    for i in color_time:fall_time
        x[i] += 1
    end
end

function simfall(times, trees)
    x = zeros(Int, times)
    color_dist = DiscreteUniform(1, times-1)
    for _ in 1:trees
        simtree(color_dist, x)
    end
    maximum(x)/trees
end