Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- #
- # Finding a space in random 3D walk
- #
- # Size of Grid
- $x = 2500;
- $y = 2500;
- $z = 2500;
- # Position of Space to find
- $a = int(rand(5000));
- $b = int(rand(5000-$a));
- $c = int(rand(5000 - $a + $b));
- $step = 0;
- while(1)
- {
- $minus = int(rand(10));
- if($minus >=5) {$xr = int(rand(100)); $x = $x - $xr;}
- else { $xr = int(rand(100)); $x = $x + $xr; }
- if($x > 10000){ $x = 9999;}
- if($x < 0){ $x = 0;}
- $minus1 = int(rand(10));
- if($minus1 >=5) {$yr = int(rand(100-$xr)); $y = $y - $yr;}
- else { $yr = int(rand(100-$xr)); $y = $y + $yr; }
- if($y > 10000){ $y = 9999;}
- if($y < 0){ $y = 0;}
- $minus2 = int(rand(10));
- if($minus2 >=5) {$zr = (100 - ($xr + $yr)); $z = $z - $zr;}
- else { $zr = (100 - ($xr + $yr)); $z = $z + $zr; }
- if($z > 10000){ $z = 9999;}
- if($z < 0){ $z = 0;}
- print "$a : $b : $c | $minus $x $xr : $minus1 $y $yr : $minus2 $z $zr\n\n";
- # How big is the space we want to find and Did we find it?
- if($x <= ($a+5) && $x >= ($a-5) && $y <= ($b+5) && $y >= ($b-5) && $z <= ($c+5) && $z >= ($c-5)){ print "WINNER: $steps\n\n"; die; }
- $step++;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement