Ugly Digit Span Exerciser

by F.

I was playing around with this “digit span” enhancer. It’s OK, but I don’t liked the timed nature of it. And I don’t have any strong feeling about how to improve at this task.

In an effort to make something that might be more effective, this morning I wrote the following Perl script. It starts with 6 digits (I mean, why start with 1 digit, as in the above-linked enhancer? Like I can’t remember that. By the time the string gets to 6, I’m already bored and thinking about lunch…mmmm…lunch.)

Anyhoo, this is ugly, and the repetition cries out for better control structures…. but whaddya gonna do. I’ve got better things to think about.

#!/usr/bin/perl -w

srand;
$basedigitspan = int(rand 999999);
$inputstring = "";
$clearstring = "";
$span = 6;
system('clear');

print "$basedigitspan \n";
$clearstring = ;
system('clear');
$inputstring= ;
chomp ($inputstring);
if ($inputstring =~ $basedigitspan) {
    print "Correct! \n";
    $span++;
} else { 
    print "More Practice! $span \n"
}

$basedigitspan = $basedigitspan.int(rand 9);
print "$basedigitspan \n";
$clearstring = ;
system('clear');
$inputstring= ;
chomp ($inputstring);
if ($inputstring =~ $basedigitspan) {
    print "Correct! \n";
    $span++;
} else { 
    print "More Practice! $span \n"
}

$basedigitspan = $basedigitspan.int(rand 9);
print "$basedigitspan \n";
$clearstring = ;
system('clear');
$inputstring=  ;
chomp ($inputstring);
if ($inputstring =~ $basedigitspan) {
    print "Correct! \n";
    $span++;
} else { 
    print "More Practice! $span \n"
}

$basedigitspan = $basedigitspan.int(rand 9);
print "$basedigitspan \n";
$clearstring = ;
system('clear');
$inputstring= ;
chomp ($inputstring);
if ($inputstring =~ $basedigitspan) {
    print "Correct! \n";
    $span++;
} else { 
    print "More Practice! $span \n"
}

$basedigitspan = $basedigitspan.int(rand 9);
print "$basedigitspan \n";
$clearstring = ;
system('clear');
$inputstring=  ;
chomp ($inputstring);
if ($inputstring =~ $basedigitspan) {
    print "Correct! $span \n";
    $span++;
} else { 
    print "More Practice! $span \n"
}

Cut the code; past it into a text editor; save with a .pl extension; and run it in a terminal. Hours of fun.

Advertisements