Advertisement
ZaynerTech

Finding a Space in a 3D Random Walk Perl

Jan 17th, 2013
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.11 KB | None | 0 0
  1. #!/usr/bin/perl
  2. #
  3. # Finding a space in random 3D walk
  4. #
  5.  
  6. # Size of Grid
  7. $x = 2500;
  8. $y = 2500;
  9. $z = 2500;
  10.  
  11.  
  12.  
  13. # Position of Space to find
  14. $a = int(rand(5000));
  15. $b = int(rand(5000-$a));
  16. $c = int(rand(5000 - $a + $b));
  17.  
  18. $step = 0;
  19. while(1)
  20. {
  21.  
  22.  $minus = int(rand(10));
  23.  if($minus >=5) {$xr = int(rand(100)); $x = $x - $xr;}
  24.  else { $xr = int(rand(100)); $x = $x + $xr; }
  25.  if($x > 10000){ $x = 9999;}
  26.  if($x < 0){ $x = 0;}
  27.  $minus1 = int(rand(10));
  28.  if($minus1 >=5) {$yr = int(rand(100-$xr)); $y = $y - $yr;}
  29.  else { $yr = int(rand(100-$xr)); $y = $y + $yr; }
  30.  if($y > 10000){ $y = 9999;}
  31.  if($y < 0){ $y = 0;}
  32.  
  33.  $minus2 = int(rand(10));
  34.  if($minus2 >=5) {$zr = (100 - ($xr + $yr)); $z = $z - $zr;}
  35.  else { $zr = (100 - ($xr + $yr)); $z = $z + $zr; }
  36.  if($z > 10000){ $z = 9999;}
  37.  if($z < 0){ $z = 0;}
  38.  
  39.  print "$a : $b : $c | $minus $x $xr : $minus1 $y $yr : $minus2 $z $zr\n\n";
  40.  
  41. # How big is the space we want to find and Did we find it?
  42. 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; }
  43.  
  44.  
  45.  
  46.  
  47. $step++;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement