Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Libraries
- using Combinatorics, StatsBase
- # Settings
- x = ["H1", "T1", "H2", "H3"]
- nflip = 3
- # Calculate all permutations for nflip trials of the x possible outcomes
- combs = collect(with_replacement_combinations(x, nflip))
- perms = []
- for i in eachindex(combs)
- perms = vcat(perms, collect(multiset_permutations(combs[i], nflip)))
- end
- # Count up the number of heads for each set of nflip trials
- nheads = []
- for i in eachindex(perms)
- perms[i] = replace.(perms[i], r"\d+" => "")
- nheads = vcat(nheads, sum(perms[i] .== "H"))
- end
- # Aggregate results by number of heads
- sort(countmap(nheads))
- sort(proportionmap(nheads))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement