#!/usr/local/bin/perl -w

%hash=();
for (;;){
    @a=(0,1,2,2,2,2,2,2,4,4);
    $x = splice @a, int rand(@a), 1;
    $y = splice @a, int rand(@a), 1;
    $z = splice @a, int rand(@a), 1;
    $q = splice @a, int rand(@a), 1;
    $num = $x.$y.$z.$q;
    if (length($num) !=4) { warn "Program corrupted"; }
#    if ($x!=0){
	$hash{$num}++;
	if ($hash{$num}==1){ $counter++; }
#    }
    last if (++$it>10_000_000);
    print "\r$it";
}
print "\n$counter\n";
for $i (sort keys %hash){
    print "$i ";
}
print "\n";


__END__
From p.ralston@comcast.net Fri Oct  8 20:07:21 2004
Date: Fri, 8 Oct 2004 18:07:21 +0000 (UTC)
From: Peter Ralston <p.ralston@comcast.net>
Newsgroups: sci.math.num-analysis
Subject: Basic Combinatorics, how to calculate the number of combinations

How would I calculate the number of combinations if the number of
objects varies?  For example:

I have 1 zero, 1 one, 6 twos, and 2 fours.  How would I figure the
number of four digit numbers that these could make?

