#!/usr/bin/ruby # #roba che mi serve: volte_che_ho_vinto_scegliendo_la_busta_di_mike = 0 volte_che_ho_vinto_tenendo_la_mia = 0 volte_che_vince_mike_subito = 0 quante_volte_lo_provo = 1000 for i in 1..quante_volte_lo_provo #concorrente busta_vincente = rand(3) + 1 scelgo_la_busta_numero = rand(3) + 1 #mike mike_apre_la_busta = 0 while mike_apre_la_busta == 0 mike_apre_la_busta = rand(3) + 1 if (mike_apre_la_busta == scelgo_la_busta_numero) then mike_apre_la_busta = 0 end end #risultati if busta_vincente == scelgo_la_busta_numero volte_che_ho_vinto_tenendo_la_mia = volte_che_ho_vinto_tenendo_la_mia + 1 elsif busta_vincente == mike_apre_la_busta volte_che_vince_mike_subito = volte_che_vince_mike_subito + 1 else volte_che_ho_vinto_scegliendo_la_busta_di_mike = volte_che_ho_vinto_scegliendo_la_busta_di_mike + 1 end end #fine del for puts "Su " + quante_volte_lo_provo.to_s puts "Se mi tenevo la mia vincevo " + volte_che_ho_vinto_tenendo_la_mia.to_s + " volte." puts "Se prendevo quella di mike vincevo " + volte_che_ho_vinto_scegliendo_la_busta_di_mike.to_s + " volte." puts "Mike ha vinto subito " + volte_che_vince_mike_subito.to_s + " volte."