line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
1669
|
use v5.24; |
|
1
|
|
|
|
|
2
|
|
2
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
3
|
1
|
|
|
1
|
|
3
|
use Test::More; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
4
|
1
|
|
|
1
|
|
534
|
use Q::S::L; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
5
|
1
|
|
|
1
|
|
5
|
use List::Util qw(sum0); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
270
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub roll_dice |
8
|
|
|
|
|
|
|
{ |
9
|
3
|
|
|
3
|
|
7
|
my ($dnd) = @_; |
10
|
|
|
|
|
|
|
|
11
|
3
|
|
|
|
|
18
|
my ($number, $faces) = $dnd =~ m{ \A (\d+) k (\d+) \z }x; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# each individual dice |
14
|
3
|
|
|
|
|
16
|
my @dice = map { superpos(1 .. $faces) } 1 .. $number; |
|
13
|
|
|
|
|
912
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# a cup of dice |
17
|
3
|
|
|
|
|
277
|
my $set = sum0 @dice; |
18
|
|
|
|
|
|
|
|
19
|
3
|
|
|
|
|
4457
|
return ($set, @dice); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my @throws = ( |
23
|
|
|
|
|
|
|
"2k6", |
24
|
|
|
|
|
|
|
"8k12", |
25
|
|
|
|
|
|
|
"3k20", |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
for my $dnd (@throws) { |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
note "Rolling $dnd..."; |
31
|
|
|
|
|
|
|
my ($set, @dice) = roll_dice $dnd; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# we roll them all at once |
34
|
|
|
|
|
|
|
my $result = $set->collapse; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# this is how we can get each individual roll |
37
|
|
|
|
|
|
|
my @rolls = map { $_->collapse } @dice; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
note "we got $result, which consisted of rolls: " . join ", ", @rolls; |
40
|
|
|
|
|
|
|
is $result, (sum0 @rolls), "result ok"; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# ... and lets roll again |
43
|
|
|
|
|
|
|
$set->reset; |
44
|
|
|
|
|
|
|
$result = $set->collapse; |
45
|
|
|
|
|
|
|
@rolls = map { $_->collapse } @dice; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
note "this time we got $result, which consisted of rolls: " . join ", ", @rolls; |
48
|
|
|
|
|
|
|
is $result, (sum0 @rolls), "result ok"; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
done_testing; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
__END__ |