Link 6 Jan 208 notes Shades Problem»

#!/usr/bin/perl
@data=<STDIN>;
@translucentFactor;
@opaqueFactor;
@lightFactor;
for ($i = 0; $i < 10; $i++)
{
   $lightFactor[$i]=100;
   $translucentFactor[$i]=0;
   $opaqueFactor[$i]=0;
}
foreach (@data)
{ 
   chomp ($_); 
   @process=split(/ /, $_);
   &processInput($process[0], $process[1], $process[2]);
   &calculateTotalLight;
}
sub processInput
{
   my $shade = $_[0];
   my $operation = $_[1];
   my $amount = $_[2];

   if ($operation eq "translucent") 
   { 
      $translucentFactor[$shade]=$amount;
   }
   else 
   { 
      $opaqueFactor[$shade]=$amount;
   }
   if ($opaqueFactor[$shade] > $translucentFactor[$shade])
   {
      $lightFactor[$shade]=100-$opaqueFactor[$shade];
   }
   else
   {
      $lightFactor[$shade]=100-($opaqueFactor[$shade]-($opaqueFactor[$shade]-$translucentFactor[$shade])/2.0);
   }
}
sub calculateTotalLight
{
   $totalLight=0;
   foreach(@lightFactor)
   {
      $totalLight+=$_;
   }
   if ($totalLight % 10 >= 5) { $totalLight += 10-$totalLight%10; }
   else {  $totalLight -=  $totalLight%10; }
   printf("%d\n", $totalLight/10);
}

  1. fuckyeahterminals posted this

Design crafted by Prashanth Kamalakanthan. Powered by Tumblr.