The Perl here is nothing special, but the result turned out to be serendipitous and funky, as well as weird. I figured this is as good a place as any to post it.
I was asked by a friend to tell him the expected value of a DND status-roll. (You roll 4d6, and discard the lowest of the four.)
#!/usr/bin/perl -w use strict; my @sums; for my $i (1..6) { for my $j (1..6) { for my $k (1..6) { for my $l (1..6) { # get the sum for this dice-roll my $min = $i; if ($j < $min) { $min = $j; } if ($k < $min) { $min = $k; } if ($l < $min) { $min = $l; } my $sum = $i+$j+$k+$l-$min; $sums[$sum]++; $sums[0]++; }}}} my $e = 0; for (3..18) { $e += $_*($sums[$_]/$sums[0]); } print "e = $e\n";
Suggestions for how to make this smaller and Perlisher are welcome. I'm sure this can be compressed to a one-liner, somehow...
Anyhoo, the expected value comes out to be 12.2445987654321... Isn't that weird?
Kinda like noticing that 9876543211 is prime...
In reply to Rolling DND Dice. by grendelkhan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |