No such thing as a small change PerlMonks

Re: Trick die rolling

by Parham (Friar)
 on Mar 10, 2002 at 23:17 UTC ( #150780=note: print w/replies, xml ) Need Help??

in reply to Trick die rolling

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 :).

Create A New User
Node Status?
node history
Node Type: note [id://150780]
help
Chatterbox?
 [james28909]: ok i have a new question ;) [james28909]: i am not sure how to ask google this either [james28909]: i am getting the current time on my machine with scalar localtime; [james28909]: i am scraping a website and retrieving a date stamp of an article. [james28909]: well time/data stamp of the article [stevieb]: james28909: what's the problem/question? [james28909]: it is not an absolute date like "27" or "31". sometimes it is like wednesday or friday [james28909]: and i need to format those special instances into an absolute date instead of "yesterday" [stevieb]: ask a question on SoPW, and include at least a half-dozen examples of the input, and at least one example of expected output

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2017-04-29 02:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
I'm a fool:

Results (531 votes). Check out past polls.