Advertisement
nalced

tsto-mining

May 31st, 2017
1,255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.29 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. # Count up number of probes for a given dig strategy.
  7. # Works by counting number of probes required to find
  8. # the gem in each of 36 squares.
  9.  
  10. # Give names to what's turned up by search
  11. # * digit x   hit gem at that square
  12. # * digit +   hit rock at that square
  13. #
  14. # Points to a list containing:
  15. # * number of squares covered in this case
  16. # * average number of digs to find gem (total)
  17.  
  18. my %strat1 = (
  19.  
  20.     # The x items mean that you hit the gem at the probe point
  21.    
  22.     "1x" => [1, 1],
  23.     "2x" => [1, 2],
  24.     "3x" => [1, 3],
  25.     "4x" => [1, 4],
  26.     "5x" => [1, 5],
  27.     "6x" => [1, 6],
  28.     "7x" => [1, 7],
  29.     "10x" => [1, 10],
  30.  
  31.     # The + items are for the shapes around probe points
  32.     "1+4" => [4, 3.5],
  33.     "2+4" => [4, 4.5],
  34.     "3+4" => [4, 5.5],
  35.     "4+3" => [3, 6.0],
  36.     "5+3" => [3, 7.0],
  37.     "6+3" => [3, 8.0],
  38.     "7+3" => [3, 9.0],
  39.  
  40.     # Treat 8 and 9 as being area probes
  41.    
  42.     "8+2" => [2, 9.0],
  43.     "9+2" => [2, 9.5],
  44. );
  45.  
  46. my %strat2 = (
  47.  
  48.     "1x" => [1, 1],
  49.     "2x" => [1, 2],
  50.     "3x" => [1, 3],
  51.     "4x" => [1, 4],
  52.     "5x" => [1, 5],
  53.     "6x" => [1, 6],
  54.     "7x" => [1, 7],
  55.     "8x" => [1, 8],
  56.     "9x" => [1, 9],
  57.     "10x" => [1, 10],
  58.     "11x" => [1, 11],
  59.     "12x" => [1, 12],
  60.  
  61.     "1+4" => [4, 3.5],
  62.     "2+4" => [4, 4.5],
  63.     "3+4" => [4, 5.5],
  64.     "4+4" => [4, 6.5],
  65.  
  66.     "5+2" => [2, 6.0],
  67.     "6+2" => [2, 7.0],
  68.     "7+2" => [2, 8.0],
  69.     "8+2" => [2, 9.0],    
  70. );
  71.  
  72. sub tally_scheme {
  73.  
  74.     my $href = shift;
  75.  
  76.     my $squares = 0;
  77.     my $total = 0.0;
  78.     foreach my $lref (values %$href) {
  79.     my ($count,$avg) = @$lref;
  80.     $squares += $count;
  81.     $total += $count * $avg;
  82.     }
  83.  
  84.     print "Counted $squares squares\n";
  85.     print "Total probes $total\n";
  86.     print "Average digs: " . ($total / $squares) . "\n";
  87. }
  88.  
  89. print "Strategy 1: max 10 digs\n";
  90. tally_scheme(\%strat1);
  91.  
  92. print "\nStrategy 2: max 12 digs\n";
  93. tally_scheme(\%strat2);
  94.  
  95. __END__
  96.  
  97. Results:
  98.  
  99. Strategy 1: max 10 digs
  100. Counted 36 squares
  101. Total probes 219
  102. Average digs: 6.08333333333333
  103.  
  104. Strategy 2: max 12 digs
  105. Counted 36 squares
  106. Total probes 218
  107. Average digs: 6.05555555555556
  108.  
  109. => strategy 2 is marginally better (seems to be because strategy 1 has
  110. an extra dig if a stone is turned up on square 8)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement