The Birthday Problem (2)

So, this is an improved version of my previous Birthday Problem. 

The major improvement was that I used “DeleteDuplicates” instead of “Union”. 

The difference in computation time is quite remarkable. DeleteDuplicates took 29 seconds, while Union took about 72 seconds. 

f[k_] := (
  count = 0;
  repeat = 10000;
   a = RandomInteger[{1, 365}, k];
   b = DeleteDuplicates[a];
   If[Length[a] != Length[b], count++
   , {i, 1, repeat}
  prob = N[count/repeat];
list = Table[f[i], {i, 1, 365}];

So, yes! Sleep is help to gain new perspective about how to do things.

And yes, there is always room for improvement. Maybe the test using Length isn’t the most efficient. I shall explore more about this next time. 


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s