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
    Uhh ... Musky? ellem was making all 1's into 2's. Your code doesn't do that. :-)

    ------
    We are the carpenters and bricklayers of the Information Age.

    The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

      I know :-)
      I don't use "fixed" dice.

        Sadly this was done because I couldn't figure out a way to reroll 1s.

        (you can see it but I filled with shame)
        --
        ellem@optonline.net
        There's more than one way to do it, but only some of them actually work.
Re: Re: Remove lowest number
by ellem (Hermit) on Aug 06, 2003 at 15:42 UTC
    Way more Perly, but I have to read this code six months from now and my code (at least to me) makes sense without commenting it to death.

    My biggest Perl obstacle is I don't use it everyday.
    --
    ellem@optonline.net
    There's more than one way to do it, but only some of them actually work.