Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.94 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. # This script calculates the Give-Value score of every blood type out there. Takes into account stuff like how many people have that blood type, how many people that blood type can donate to, and how many people those receivers can receive from. The higher your blood type's score, the more valuable you are as an individual blood donator.
  4. # Paul Nickerson (pgn674)
  5.  
  6. use strict;
  7. use warnings;
  8. use strict 'refs';
  9. use Switch;
  10.  
  11.             #   O-O+B-B+A-A+AB-AB+
  12. my @depGraph = ([1,0,0,0,0,0,0,0],#O-   Dependancy graph. Top row can give to right column - $depGraph[take][give]
  13.                 [1,1,0,0,0,0,0,0],#O+
  14.                 [1,0,1,0,0,0,0,0],#B-
  15.                 [1,1,1,1,0,0,0,0],#B+
  16.                 [1,0,0,0,1,0,0,0],#A-
  17.                 [1,1,0,0,1,1,0,0],#A+
  18.                 [1,0,1,0,1,0,1,0],#AB-
  19.                 [1,1,1,1,1,1,1,1]);#AB+
  20. my @ratioChart = (0.077,0.384,0.017,0.094,0.065,0.323,0.007,0.032); # Portion of population with these blood types in this order:| 0: O- | 1: O+ | 2: B- | 3: B+ | 4: A- | 5: A+ | 6: AB- | 7: AB+ |
  21. my $scoreFor;   # Each blood type I'm calculating a score for.
  22. my $giveTo;     # Each blood type that scoreFor can give to.
  23. my $takeFrom;   # Each blood type that giveTo can take from.
  24. my $howWellOff; # How well off each recipient is, meaning how many people they can take from.
  25. my $howNeeded;  # How needed (or how valuable) each individual blood donor is. The final score.
  26. my $howWanted;  # How much each blood type as a whole group is wanted (before taking into acount how many people there are of those blood types), meaning how many people can take their blood, divided by how well off they are.
  27.  
  28. print "Finding Give-Value scores.\n";
  29.  
  30. for($scoreFor=0; $scoreFor<8; $scoreFor++)  # Calculating score for this type (call it type1, or scoreFor).
  31. {
  32.     $howNeeded=0;
  33.     $howWanted=0;
  34.     for($giveTo=0; $giveTo<8; $giveTo++)    # Testing if type1 can give to this type (call it type2, or giveTo).
  35.     {
  36.         if($depGraph[$giveTo][$scoreFor])   # type1 can give to type2
  37.         {
  38.             $howWellOff=0;
  39.             for($takeFrom=0; $takeFrom<8; $takeFrom++)  # Seeing if type2 can take from this type (call it type3, or takeFrom).
  40.             {
  41.                 if($depGraph[$giveTo][$takeFrom])   # type2 can take from type3
  42.                 {
  43.                     $howWellOff = $howWellOff + $ratioChart[$takeFrom];
  44.                 }
  45.             }
  46.             $howWanted = $howWanted + $ratioChart[$giveTo] / $howWellOff;
  47.         }
  48.     }
  49.     $howNeeded = $howWanted / $ratioChart[$scoreFor];
  50.     switch ($scoreFor)
  51.     {
  52.         case 0  {print "O- "}
  53.         case 1  {print "O+ "}
  54.         case 2  {print "B- "}
  55.         case 3  {print "B+ "}
  56.         case 4  {print "A- "}
  57.         case 5  {print "A+ "}
  58.         case 6  {print "AB-"}
  59.         case 7  {print "AB+"}
  60.         else    {print "SWITCH STATEMENT ERROR"}
  61.     }
  62.     print " : $howNeeded\n";
  63. }
  64.  
  65. # Give-Value score of blood type X = cycle through each blood type for this sum((portion of population of this [cycled] blood type that can receive from X [how many people can use X])/(portion of population that each of those recipient blood types can receive from [how well off those recipients are]))/(portion of population that is X [how common X are])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement