in reply to Remove lowest number
Here is a subset of code that I had written to solve the problem. The essential ingredients are there.
#!/usr/bin/perl -w use strict; use warnings; use diagnostics; my @rolls=(); foreach (0..7){ $rolls[$_]=d2d6(); } my @keys=sort {$a cmp $b} @rolls; my %ptr=map { $_ => 1 } @keys; $ptr{$keys[0]}=0; my @cull = grep $ptr{$_} ,@rolls; print "Sorted: ",join(" ",@keys),"\n"; print "Before culling: ",join(" ",@rolls),"\n"; print "After culling: ",join(" ",@cull),"\n"; exit(0); sub d1d6 { return int(rand(6))+1; } sub d2d6 { return d1d6() + d1d6(); }
Running the code produces:
You can see the problem with is that it removes duplicates of the rolled number as well. You can modify the code to count the number of occurances and then ignore the first occurance and print the rest of the occurances.# perl dice.pl Sorted: 3 3 4 5 7 7 7 9 Before culling: 3 5 7 4 7 9 7 3 After culling: 5 7 4 7 9 7
I've used variants this code to generate FRP gaming information in the past where the system was to roll N+2 number of rolls plus one and ignore the lowest and highest roll.
Peter @ Berghold . Net
Sieze the cow! Bite the day!
Test the code? We don't need to test no stinkin' code! All code posted here is as is where is unless otherwise stated.
Brewer of Belgian style Ales
|
|---|