Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- #Enter target area here
- $targetminx = 0;
- $targetmaxx = 200;
- $targetminy = -200;
- $targetmaxy = -150;
- $highesty = 0;
- %loader = ();
- for ($xvel = 0; $xvel < 200; $xvel++) {
- for ($yvel = -200; $yvel < 200; $yvel++) {
- #print "Trying: $xvel -- $yvel\n";
- $samplex = $xvel;
- $sampley = $yvel;
- $xstart = 0;
- $ystart = 0;
- $tempy = 0;
- while (($xstart < $targetmaxx)&&($ystart > $targetminy)) { #If we are past max-x or max-y then we will never get there so try next
- $xstart = $xstart + $samplex;
- $ystart = $ystart + $sampley;
- if ($ystart > $tempy) {
- $tempy = $ystart; #Record highest value of this trajectory
- }
- if ($samplex < 0) { $samplex++; } else { if ($samplex > 0) { $samplex--; } } #Do drag calc.
- $sampley--; #Do gravity calc
- if (($xstart > $targetminx - 1) && ($xstart < $targetmaxx + 1) && ($ystart > $targetminy - 1) && ($ystart < $targetmaxy + 1)) { #If within target area
- $loader{$xvel.",".$yvel} = 1; #Record for part2
- if ($tempy > $highesty) { #If this trajectory's highest value is highest among all trajectory values
- $highesty = $tempy; #Then record it
- }
- }
- }
- }
- }
- print $highesty."\n"; #part1
- print scalar(keys %loader)."\n"; #part2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement