Advertisement
Guest User

Untitled

a guest
Mar 16th, 2024
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. # Libraries
  2. using Combinatorics, StatsBase
  3.  
  4.  
  5. # Settings
  6. x = ["H1", "T1", "H2", "H3"]
  7. nflip = 3
  8.  
  9.  
  10. # Calculate all permutations for nflip trials of the x possible outcomes
  11. combs = collect(with_replacement_combinations(x, nflip))
  12. perms = []
  13. for i in eachindex(combs)
  14. perms = vcat(perms, collect(multiset_permutations(combs[i], nflip)))
  15. end
  16.  
  17.  
  18. # Count up the number of heads for each set of nflip trials
  19. nheads = []
  20. for i in eachindex(perms)
  21. perms[i] = replace.(perms[i], r"\d+" => "")
  22. nheads = vcat(nheads, sum(perms[i] .== "H"))
  23. end
  24.  
  25.  
  26. # Aggregate results by number of heads
  27. sort(countmap(nheads))
  28. sort(proportionmap(nheads))
  29.  
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement