vuralarm.blogg.se

How to put ti nspire cx cas software on ti nspire cx
How to put ti nspire cx cas software on ti nspire cx










how to put ti nspire cx cas software on ti nspire cx

Here’s a short Python program that demonstrates this action.

how to put ti nspire cx cas software on ti nspire cx

After all, as shown above, with 23 guests the odds are greater than 50–50 that there’s a match.īut it turns out that you need to let in 25 guests, on average, before you find any two guests with shared birthdays! Instead of letting 23 people in the door, and then comparing birthdays, let’s let the party-goers in one at a time.Īs each guest arrives, we add their birthday number to a list, checking to see if they match any of the guest’s birthdays that are already on the list.Īs soon as we find a match we stop letting in any more guests and tally how many it took to get two guests with the same birthday.Īfter ten thousand parties you’d think the average number of guests for finding a match should be just less than 23. The fraction of times this happens during all the 10,000 parties is calculated, and it averages out to just slightly more than half the time. The choices() function uses “with replacement”, which means that the days selected can possibly repeat in the list that’s returned.īy converting this list of 23 guest birthdays into a set, any repeats are removed, making the set’s count less than 23 if any two guests share a birthday. For each party, a set of 23 days are selected randomly from the list of days, to create a list of 23 guest_birthdays.

how to put ti nspire cx cas software on ti nspire cx

The variable days is a list of the integers 0 to 364, each representing one day of a typical 365-day year. import random parties = 10000 hits = 0 days = list(range(365)) for i in range(parties): guest_birthdays = random.choices(days, k=23) if len(set(guest_birthdays)) < 23: hits += 1 print(hits / parties) Let me explain.įirst, here’s a short Python program that agrees with all the experts, and it makes sense. When I programmed this, I discovered a very strange result that I’m still trying to wrap my head around. Sure, you can find a probability formula (look in Wikipedia to find it) but simulating the situation can be fun and enlightening. How many people need to be at a party on average, so that at least two of them share a birthday? This is the kind of problem that Python shines at when you tackle it with a Monte Carlo simulation.












How to put ti nspire cx cas software on ti nspire cx