# W1_Lab2 - problem_2 vs problem_3

I need some assistance with figuring out the difference between birthday problem 2 and 3. Given the solutions, both seem identical where in both problems you’re working with the birthday of a student in the student-set. I’m not sure I understand the subtlety of explicitly choosing the 1st student’s birthday and looking for a match (problem 2) VS getting all unique count of students with different birthdays and then figuring out if unique count is different than original student count.

Adding the python code here as well for convenience:

def problem_2(n_students):
# Generate birthdays for every student
gen_bdays = np.random.randint(0, 365, (n_students))

``````# Pick one student at random
rnd_index = np.random.randint(0, len(gen_bdays))

# Get the bday from the selected student
rnd_bday = gen_bdays[rnd_index]

# Take the bday out of the pool of bdays (otherwise there is always a match)
remaining_bdays = np.delete(gen_bdays, rnd_index, axis=0)

# Check if another student shares the same bday
return rnd_bday in remaining_bdays
``````

=====================

problem_3(n_students):

``````# Generate birthdays for every student
gen_bdays = np.random.randint(0, 365, (n_students))

# Get array containing unique bdays
unique_bdays = np.array(list(set(gen_bdays)))

# Check that both the original and unique arrays have the same length
# (if so then no two students share the same bday)
return len(unique_bdays) != len(gen_bdays)
``````

Update: I thinking typing out my thoughts might have helped, in the problem_2 we’ve chosen 1 specific birthday, whereas problem_3 doesn’t center around 1 single student’s birthday but ‘any’ student’s birthday. And that does change the probability of finding a match. Am I missing anything?

1 Like