Hi,
I had some spare time and write a perl version of dr. kamigawas brain
age / Big Brain Academy.
There are 6 Memory and Calculation tests. You need the Moduls
Heap-Simple and Time::HiRes.
If somebody adds further tests/games etc. please mail back.

Have Fun!


#!/usr/local/bin/perl
use Heap::Simple;
use Time::HiRes;

########################################################################
########

my @abc = (a .. z);
my $chars1 = 0;
my $chars2 = 0;
my $chars3 = 0;
my $chars4 = 0;
my $chars5 = 0;
my $string = undef;
$right = 0;
$wrong = 0;
$turns = 0;
# start timer
$start = time();

while ($turns <= 10){
  $chars1 = int(rand(26));
  $chars2 = int(rand(26));
  $chars3 = int(rand(26));
  $chars4 = int(rand(26));
  $chars5 = int(rand(26));
  $string = $abc[$chars1] . $abc[$chars2] . $abc[$chars3] .
$abc[$chars4] . $abc[$chars5];
  print "Keep the letters in mind!\n $string\n";
  sleep(1.5);
  for ( my $i = 1; $i <= 30; $i++) {
   print "\n\n\n\n\n\n\n\n\n\n";
  }
  print "Enter:\n";
  $input = <STDIN>;
  chomp($input);
  if ( $input eq $string ) {
    print "Very Good. $input is right! Feel Happy!\n";
    $right++;
  } else {
    print "$input is wrong!!! Bad! Stupid!\n";
    $wrong++;
  }
  $turns++;
}
# end timer
$end = time();
$tsum = ($end - $start);
print "Right: $right  Wrong: $wrong\nIn $tsum seconds!";
$score += &score($right, $wrong, $tsum, '-0.2');
print "Your Score is $score!\n";


########################################################################
########


my $chars1 = 0;
my $chars2 = 0;
$right = 0;
$wrong = 0;
$turns = 0;
# start timer
$start = time();

while ($turns <= 10){
  $chars1 = int(rand(100));
  $chars2 = int(rand(100));
  print "Please Calculate: $chars1 + $chars2\n";
  print "Enter result:\n";
  $input = <STDIN>;
  chomp($input);
  if ($input == ($chars1 + $chars2)) {
    print "Very Good. $input is right!\n";
    $right++;
  } else {
    print "$input is wrong!!! Bad! Stupid!\n";
    $wrong++;
  }
  $turns++;
}
# end timer
$end = time();
$tsum = ($end - $start);
print "Right: $right  Wrong: $wrong\nIn $tsum seconds!";
$score += &score($right, $wrong, $tsum, '-0.5');
print "Your Score is $score!\n";

########################################################################
########

my @abc = (a .. z);
my $chars1 = 0;
my $chars2 = 0;
$right = 0;
$wrong = 0;
$turns = 0;
# start timer
$start = time();

while ($turns <= 10){
  $chars1 = int(rand(26));
  $chars2 = int(rand(26));
  print "Which letter comes first?\n 1. $abc[$chars1] 2.
$abc[$chars2]\n";
  print "Enter:\n";
  $input = <STDIN>;
  chomp($input);
  if ( ($input == 1) && ($chars1 < $chars2)) {
    print "Very Good. $input is right!\n";
    $right++;
  } elsif ( ($input == 2) && ($chars2 < $chars1)) {
    print "Very Good. $input is right!\n";
    $right++;
  } elsif ( ($input == 0) && ($chars1 == $chars2)) {
    print "Very Good. $input is right!\n";
    $right++;
  } else {
    print "$input is wrong!!! Bad! Stupid!\n";
    $wrong++;
  }
  $turns++;
}
# end timer
$end = time();
$tsum = ($end - $start);
print "Right: $right  Wrong: $wrong\nIn $tsum seconds!";
$score += &score($right, $wrong, $tsum, '-0.5');
print "Your Score is $score!\n";

########################################################################
########

my @list = ();
my $right = 0;
my $wrong = 0;
my $turns = 0;

# start timer
my $start = time();

while ($turns < 10) {
  $list[1] = int(rand(100000));
  $list[2] = int(rand(100000));
  print "Tell me which number is the largest (1. or 2.):\n";
  print "1. $list[1]            2.  $list[2]\n";
  my $input = <STDIN>;
  chomp($input);

  my $heap =  Heap::Simple->new(order => ">");
  $heap->insert($list[1], $list[2]);
  $count = $heap->count;
  my $larg = $heap->top;
  print "$larg $count\n";
  if ( $larg == $list[$input] ) {
    print "Very Good. $input is right!\n";
    $right++;
  } else {
    print "$input is wrong!!! Bad! Stupid!\n";
    $wrong++;
  }
  $turns++;
}
# end timer
my $end = time();
my $tsum = ($end - $start);
print "Right: $right  Wrong: $wrong\nIn $tsum seconds!";
$score += &score($right, $wrong, $tsum, '-5');
print "Your Score is $score!\n";

########################################################################
########
$right = 0;
$wrong = 0;
# start timer
$start = time();
$turns = 0;
while ($turns < 10) {
  print "How many charakters do you see?\n";
  $chars = int(rand(16))+1;
  $lb =  int(rand(8));
  for ( my $i = 1; $i <= $chars; $i++) {
    print "*";
    if ($i == $lb ) {
      print "\n";
      $lb = int(rand(8));
    }
  }
  print "\nEnter:\n";
  my $input = <STDIN>;
  chomp($input);
  if ( $chars == $input) {
    print "Very Good. $input is right!\n";
    $right++;
  } else {
    print "$input is wrong!!! Bad! Stupid!\n";
    $wrong++;
  }
  $turns++;
}
# end timer
$end = time();
$tsum = ($end - $start);
print "Right: $right  Wrong: $wrong\nIn $tsum seconds!";
$score += &score($right, $wrong, $tsum, '-0.5');
print "Your Score is $score!\n";

########################################################################
########
$right = 0;
$wrong = 0;
# start timer
$start = time();
$turns = 0;
sleep(2);
while ($turns < 10) {
  print "Keep the numbers in Mind!\n";
  $chars = int(rand(999999))+1;
  print "$chars\n";
  sleep(2);
  for ( my $i = 1; $i <= 30; $i++) {
   print "\n\n\n\n\n\n\n\n\n\n";
  }
  print "Enter:\n";
  my $input = <STDIN>;
  chomp($input);
  if ( $chars == $input) {
    print "Very Good. $input is right!\n";
    $right++;
  } else {
    print "$input is wrong!!! Bad! Stupid!\n";
    $wrong++;
  }
  $turns++;
}
# end timer
$end = time();
$tsum = ($end - $start);
print "Right: $right  Wrong: $wrong\nIn $tsum seconds!";
$score += &score($right, $wrong, $tsum, '0');
print "Your Score is $score!\n";


########################################################################
########
sub score {
  my $right = shift;
  my $wrong = shift;
  my $seconds = shift;
  my $tb = shift;
  
  my $points = 10*$right;
  my $failures = -10*$wrong;
  my $tpoints = $tb*$seconds;

  my $score = $points+$failures+$tpoints;
  return ($score);
}
########################################################################
########


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to