File Exchange Pick of the Week

Our best user submissions

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the Original version of the page.

ShakespeareInsult 3

Posted by Will Campbell,

Will‘s pick this week is ShakespeareInsult by Jos (10584).

Shall I compare thee to a summer’s day? Or perhaps something less flattering? What to do if the muses escape you and you can’t come up with that perfectly poetic insult? Well look no further than the ShakespeareInsult function.

Based on the Shakespeare Insult Kit, the function randomly chooses three words from three columns each containing 50 words. Precede a random combination with a “Thou,” and you have yourself some bard-inspired slander. I modified the code slightly to have it spit out 20 insults per call:


I don’t exactly know why, but I’m reminded of another function that ships with MATLAB… In any event, of the ones I generated, I think that gorbellied tickle-brained lout is my favorite. Brownie points if you can tell me the total number of possible insults given that there are 50 choices for each word. Bigger brownie points if you can tell me how many times I’d have to generate a random insult before I can say with 95% certainty that I’ve seen all of them. Or just sit back, relax, and let the insults fly.

Let us know what you think here or leave a comment for Jos (10584).


Comments are closed.

3 CommentsOldest to Newest

Alex R. replied on : 1 of 3
Correct me if I am wrong, but I believe that there are 125,000 possible insults. Mathematically, it is just 50x50x50. I confirmed this by writing a small script that iterated through each possible combination and summed the total amount of outcomes. Out of the 125,000 insults that I generated, I have to say that "Thou frothy fly-bitten fustilarian" is my personal favorite. This generator seems like it may be useful during rush-hour!
Ben Petschel replied on : 2 of 3
In probability theory this is known as the coupon collector's problem. According to the Wikipedia page, there is an asymptotic result that if T is the number of tries needed to collect the whole set, then P(T exp(-exp(-c)) as n->inf. Solving this for c with n=125000, we find that you need 1,838,283 tries to have a 95% chance of collecting the whole set. Monte Carlo with 1000 simulations (takes about 30 sec on a decent computer) gets probability of 94.7% which is pretty close. Here's the code I used:
n = 125000; % number of coupons
p = 0.95; % desired probability
t = floor(n*log(n)+(-log(-log(p)))*n); % predicted number required for P(T<t)=p
N = 1000; % number of MC

% Monte Carlo simulation
x = false(1,N);
for i = 1:N
  v = false(1,n);
  v(randi(n,t,1)) = true;
  x(i) = all(v);
mean(x+0) % should be close to p