Advertisement
Guest User

Untitled

a guest
Dec 16th, 2021
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.49 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3.  
  4. #Enter target area here
  5. $targetminx = 0;
  6. $targetmaxx = 200;
  7.  
  8. $targetminy = -200;
  9. $targetmaxy = -150;
  10.  
  11.  
  12.  
  13. $highesty = 0;
  14. %loader = ();
  15.  
  16. for ($xvel = 0; $xvel < 200; $xvel++) {
  17. for ($yvel = -200; $yvel < 200; $yvel++) {
  18.  
  19. #print "Trying: $xvel -- $yvel\n";
  20.  
  21.         $samplex = $xvel;
  22.         $sampley = $yvel;
  23.         $xstart = 0;
  24.         $ystart = 0;
  25.         $tempy = 0;
  26.         while (($xstart < $targetmaxx)&&($ystart > $targetminy)) { #If we are past max-x or max-y then we will never get there so try next
  27.                 $xstart = $xstart + $samplex;
  28.                 $ystart = $ystart + $sampley;
  29.  
  30.                 if ($ystart > $tempy) {
  31.                         $tempy = $ystart; #Record highest value of this trajectory
  32.                 }
  33.  
  34.                 if ($samplex < 0) { $samplex++; } else { if ($samplex > 0) { $samplex--; } } #Do drag calc.
  35.                 $sampley--; #Do gravity calc
  36.  
  37.                 if (($xstart > $targetminx - 1) && ($xstart < $targetmaxx + 1) && ($ystart > $targetminy - 1) && ($ystart < $targetmaxy + 1)) { #If within target area
  38.                         $loader{$xvel.",".$yvel} = 1; #Record for part2
  39.                         if ($tempy > $highesty) { #If this trajectory's highest value is highest among all trajectory values
  40.                                 $highesty = $tempy; #Then record it
  41.                         }
  42.  
  43.                 }
  44.         }
  45.  
  46. }
  47. }
  48.  
  49. print $highesty."\n"; #part1
  50. print scalar(keys %loader)."\n"; #part2
  51.  
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement