in any 1 roll, it rerolls the lowest number. It will also add the three highest sets of rolls and print it out. I know my version isn't as well done as others, but i didn't sit down to really work with it.. just fixed your code here and there to try and keep as much of it intact :).
#!/usr/bin/perl
use warnings;
use strict;
#Die Roller: uses 4d6 discarding the lowest number
#rerolling any roll of 1
my $roll = 6;
my @sums;
until ($roll == 0) {
my @d6;
chomp $roll;
$roll--;
$d6[0] = int(rand(6) + 1);
$d6[1] = int(rand(6) + 1);
$d6[2] = int(rand(6) + 1);
$d6[3] = int(rand(6) + 1);
@d6 = sort @d6;
$d6[0] = int(rand(6) + 1); #reroll lowest number
my $sum = $d6[0] + $d6[1] + $d6[2] + $d6[3];
push(@sums, $sum);
print "$d6[0], $d6[1], $d6[2], $d6[3] : $sum\n\n";
}
@sums = sort @sums;
my $three_highest = $sums[3] + $sums[4] + $sums[5]; #add three highest
+ numbers in array
print "total of three highest roles : $three_highest";
EDIT... posted too quick and didn't even read your post in whole (missed the reroll of ONLY 1's)... i guess you didn't want one that looked like your version either :P, nonetheless, i'll keep the code here for you :).
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.