in reply to Remove lowest number
I took some of your code, some of my own and added in jeffa's summation snippet for good measure.
#! /usr/local/bin/perl use diagnostics; use warnings; use strict; use Games::Dice 'roll_array'; # this module rocks (well rolls anyway + ;-) use List::Util qw(sum); my $rolls = 6; for my $roll (1 .. $rolls) { # how many sets of dice rolls determin +ed by the value of $rolls my @rolls = roll_array '4d6'; # magic ;-) print "raw rolls: @rolls\n"; @rolls = sort @rolls; # sorted lowest to highest shift @rolls; # remove the lowest value by shifting +it off print "top three rolls: @rolls\n"; my $sum = sum(@rolls); # List::Util's sum print "total: $sum\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Remove lowest number
by dragonchild (Archbishop) on Aug 06, 2003 at 15:52 UTC | |
by Mr. Muskrat (Canon) on Aug 06, 2003 at 15:55 UTC | |
by ellem (Hermit) on Aug 06, 2003 at 16:04 UTC | |
by l2kashe (Deacon) on Aug 06, 2003 at 16:30 UTC | |
|
Re: Re: Remove lowest number
by ellem (Hermit) on Aug 06, 2003 at 15:42 UTC |