Skip to content

Instantly share code, notes, and snippets.

@nickmarden
Last active December 7, 2017 01:31
Show Gist options
  • Save nickmarden/579d25c80a3fa2a8d69c7f5332f93f95 to your computer and use it in GitHub Desktop.
Save nickmarden/579d25c80a3fa2a8d69c7f5332f93f95 to your computer and use it in GitHub Desktop.
All the multiplication tables you can eat.
#!/usr/bin/perl -w
use strict;
my $ROWS = 10;
my $COLS = 5;
my $MAX = 12;
print "\n\n\n\n";
my $q = { };
my $row_count = $ROWS;
while($row_count--) {
my $problems = [];
my $col_count = $COLS;
while($col_count--) {
my $a;
my $b;
do {
$a = int(rand($MAX+1));
$b = int(rand($MAX+1));
} while(exists $q->{"${a}_${b}"});
push @$problems, [ $a, $b ];
$q->{"${a}_${b}"} = 1;
}
printf(" %2d"x$COLS . "\n", map { $_->[0] } @$problems);
printf(" X %2d"x$COLS . "\n", map { $_->[1] } @$problems);
print(" ------"x$COLS, "\n\n\n");
}
print "\n\n";
print "Time: ____ min _____ seconds\n\n\n";
print "Number correct: ______/" . ($COLS*$ROWS) . "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment