#! /usr/bin/perl

$M = 50;

# compile file

if (-e "partitions")
{
    print "partitions already exists\n";
}
else
{
    system "g++ partitions.cc -o partitions";
}

# generate all partitions

for ($p = 1; $p <= $M; $p++)
{
    $pfile = "p$p";

    print "checking $pfile ... \n";

    if (-e $pfile)
    {
        print "$pfile already exists\n";
    }
    elsif ($pfile eq "p1")
    {
        system "echo 1 > p1";
    }
    else
    {
        system "partitions $p; sort -nr $pfile | uniq > tmp; mv tmp $pfile";
    }
}
