#!/bin/bash
# Monte Carlo analysis of birthday problem.
# What are the odds at least 3 people in a group of 11 will share a birthday?
# Number reported is number of times this happens out of 100,000 tries.
# For Perl and other one-liners, see http://www.nationmaster.com/encyclopedia/Birthday-problem
# rwhe@ludism.org, 2008-08-18 

rm matchcount.txt
touch matchcount.txt

for ((i=1;i<=100000;i+=1)); do
  perl -e 'for (1..11) {$h{int(rand(365)+1)}++}; for (keys %h) {print $_, ": ", $h{$_}, " times\n" if $h{$_} > 2}' >> matchcount.txt
done

wc -l matchcount.txt
