Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- # Count up number of probes for a given dig strategy.
- # Works by counting number of probes required to find
- # the gem in each of 36 squares.
- # Give names to what's turned up by search
- # * digit x hit gem at that square
- # * digit + hit rock at that square
- #
- # Points to a list containing:
- # * number of squares covered in this case
- # * average number of digs to find gem (total)
- my %strat1 = (
- # The x items mean that you hit the gem at the probe point
- "1x" => [1, 1],
- "2x" => [1, 2],
- "3x" => [1, 3],
- "4x" => [1, 4],
- "5x" => [1, 5],
- "6x" => [1, 6],
- "7x" => [1, 7],
- "10x" => [1, 10],
- # The + items are for the shapes around probe points
- "1+4" => [4, 3.5],
- "2+4" => [4, 4.5],
- "3+4" => [4, 5.5],
- "4+3" => [3, 6.0],
- "5+3" => [3, 7.0],
- "6+3" => [3, 8.0],
- "7+3" => [3, 9.0],
- # Treat 8 and 9 as being area probes
- "8+2" => [2, 9.0],
- "9+2" => [2, 9.5],
- );
- my %strat2 = (
- "1x" => [1, 1],
- "2x" => [1, 2],
- "3x" => [1, 3],
- "4x" => [1, 4],
- "5x" => [1, 5],
- "6x" => [1, 6],
- "7x" => [1, 7],
- "8x" => [1, 8],
- "9x" => [1, 9],
- "10x" => [1, 10],
- "11x" => [1, 11],
- "12x" => [1, 12],
- "1+4" => [4, 3.5],
- "2+4" => [4, 4.5],
- "3+4" => [4, 5.5],
- "4+4" => [4, 6.5],
- "5+2" => [2, 6.0],
- "6+2" => [2, 7.0],
- "7+2" => [2, 8.0],
- "8+2" => [2, 9.0],
- );
- sub tally_scheme {
- my $href = shift;
- my $squares = 0;
- my $total = 0.0;
- foreach my $lref (values %$href) {
- my ($count,$avg) = @$lref;
- $squares += $count;
- $total += $count * $avg;
- }
- print "Counted $squares squares\n";
- print "Total probes $total\n";
- print "Average digs: " . ($total / $squares) . "\n";
- }
- print "Strategy 1: max 10 digs\n";
- tally_scheme(\%strat1);
- print "\nStrategy 2: max 12 digs\n";
- tally_scheme(\%strat2);
- __END__
- Results:
- Strategy 1: max 10 digs
- Counted 36 squares
- Total probes 219
- Average digs: 6.08333333333333
- Strategy 2: max 12 digs
- Counted 36 squares
- Total probes 218
- Average digs: 6.05555555555556
- => strategy 2 is marginally better (seems to be because strategy 1 has
- an extra dig if a stone is turned up on square 8)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement