#!/usr/bin/perl $filename ="problems.dat"; $MAXLINES=25; open(PROBLEMS, "< $filename") || die ("couldn't open $filename: $!\n"); @filecontents =; close(PROBLEMS); my @zadachi; my $line; # parsing the file for $line (0..@filecontents) { $filecontents[$line] =~ s/\s//; @{$zadachi[$line]}=split(/\,/, $filecontents[$line]); # print "$filecontents[$line]\n"; # print "${$zadachi[$line]}[2]\n"; } my $filelength=scalar(@zadachi); # print "file length is $filelength\n"; my @oldzadachi=@zadachi; @zadachi=(); for $line (0..$filelength) { my $numzadach=scalar(@{$oldzadachi[$line]}); # print "line is $line, numzadach is $numzadach\n"; if ($numzadach) { # print "Pushing $line to zadachi\n"; push(@zadachi,@oldzadachi[$line]); } } my $numlines=scalar(@zadachi)-1; # print "We finished parsing now... there are $numlines lines\n"; for $i (0..$MAXLINES) { print "\#$i:\t"; for $line (0..$numlines) { $invalid=1; $numzad=scalar(@{$zadachi[$line]}); while ($invalid) { $starred=0; $starredone=0; $starredtwo=0; $starredthree=0; # print "zadachi is $numzad, line is $line, numlines=$numlines\n"; $num=int(rand($numzad)); $morenum=int(rand($numzad)); $moremorenum=int(rand($numzad)); # print "$num, $morenum\n"; if ( ${$zadachi[$line]}[$num] =~/\*/) { #print "starredone!"; $starredone=1; $starred++; } if ( ${$zadachi[$line]}[$morenum] =~/\*/) { #print "starredtwo!"; $starredtwo=1; $starred++; } if ( ${$zadachi[$line]}[$moremorenum] =~/\*/) { #print "starredthree!"; $starredthree=1; $starred++; } $invalid=(($num >= $morenum) || ($morenum >= $moremorenum) || ($num >= $moremorenum)); if ($starred> 1) { #print "invalid-star! "; $invalid= 1; } } if($starredone) { print "${$zadachi[$line]}[$num], ${$zadachi[$line]}[$morenum],\t| "; } elsif($starredtwo) { print "${$zadachi[$line]}[$morenum], ${$zadachi[$line]}[$moremorenum],\t| "; } elsif($starredthree) { print "${$zadachi[$line]}[$num], ${$zadachi[$line]}[$moremorenum],\t| "; } else { print "${$zadachi[$line]}[$num], ${$zadachi[$line]}[$morenum], ${$zadachi[$line]}[$moremorenum],\t| "; } } print "\n"; print "\n"; print "\n"; }