Month: March 2017

Monty Hall Problem in Ruby

Just for fun, the monty hall problem in ruby. Runs simulation one million times. def monty_hall(switch) results = {switching: switch, wins: 0, losses: 0, count: 0, win_percentage: 0} (10**6).times.each do |n| prizes = [0,0,1].shuffle initial_selection = (0..2).to_a.sample other_doors = (0..2).to_a – [initial_selection] goat = other_doors.select{|n| prizes[n]==0}.sample available_selections = [initial_selection, (0..2).to_a – [initial_selection, goat]].flatten if switch […]