line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Lotter; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
20949
|
use base qw( Class::Accessor::Fast ); |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
5277
|
|
4
|
5
|
|
|
5
|
|
19205
|
use strict; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
136
|
|
5
|
5
|
|
|
5
|
|
26
|
use warnings; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
169
|
|
6
|
5
|
|
|
5
|
|
6484
|
use Data::Dumper; |
|
5
|
|
|
|
|
71982
|
|
|
5
|
|
|
|
|
439
|
|
7
|
5
|
|
|
5
|
|
49
|
use constant DEBUG => $ENV{DATA_LOTTER_DEBUG}; |
|
5
|
|
|
|
|
51
|
|
|
5
|
|
|
|
|
324
|
|
8
|
5
|
|
|
5
|
|
68
|
use 5.8.1; |
|
5
|
|
|
|
|
16
|
|
|
5
|
|
|
|
|
5032
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.00004'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw(lists available )); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
*debug = DEBUG |
15
|
|
|
|
|
|
|
? sub { |
16
|
|
|
|
|
|
|
my $mess = shift; |
17
|
|
|
|
|
|
|
print STDERR $mess, "\n"; |
18
|
|
|
|
|
|
|
} |
19
|
700033
|
|
|
700033
|
|
12172823
|
: sub { }; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
22
|
100002
|
|
|
100002
|
1
|
822864
|
my $class = shift; |
23
|
100002
|
|
|
|
|
305906
|
my %lists = @_; |
24
|
|
|
|
|
|
|
|
25
|
100002
|
|
|
|
|
202358
|
_scale_up(\%lists); |
26
|
|
|
|
|
|
|
|
27
|
100002
|
|
|
|
|
134495
|
my $cumulative = 0; |
28
|
100002
|
|
|
|
|
206961
|
foreach my $weight ( values %lists ) { |
29
|
500010
|
|
|
|
|
461433
|
$weight = int($weight); |
30
|
500010
|
|
|
|
|
647529
|
$cumulative += $weight; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
100002
|
|
|
|
|
564319
|
return $class->SUPER::new( { available => $cumulative, lists => \%lists } ); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _scale_up{ |
37
|
100007
|
|
|
100007
|
|
120997
|
my $lists_ref = shift; |
38
|
|
|
|
|
|
|
|
39
|
100007
|
|
|
|
|
101456
|
my ($i,$j); |
40
|
100007
|
|
|
|
|
328706
|
while ( my ( $key, $value ) = each %$lists_ref ) { |
41
|
500025
|
|
|
|
|
629347
|
$value =~ /\.(\d+)/; |
42
|
500025
|
100
|
|
|
|
1021424
|
$1 and $i = length $1; |
43
|
500025
|
100
|
100
|
|
|
1055289
|
if( !$j or $i > $j ){ |
44
|
500021
|
|
|
|
|
1529549
|
$j = $i; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
100007
|
100
|
|
|
|
238179
|
if($j){ |
48
|
3
|
100
|
|
|
|
9
|
$j = 6 if $j > 6; |
49
|
3
|
|
|
|
|
4
|
my $scale = 10 ** $j; |
50
|
3
|
50
|
|
|
|
9
|
if($scale > 1){ |
51
|
3
|
|
|
|
|
8
|
for(keys(%$lists_ref)){ |
52
|
9
|
|
|
|
|
23
|
$lists_ref->{$_} *= $scale; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub pickup { |
59
|
100003
|
|
|
100003
|
1
|
1301545
|
my $self = shift; |
60
|
100003
|
|
|
|
|
119465
|
my $num = shift; |
61
|
100003
|
|
100
|
|
|
217669
|
my $remove = shift || ''; |
62
|
100003
|
|
|
|
|
102950
|
my @ret; |
63
|
|
|
|
|
|
|
|
64
|
100003
|
|
|
|
|
266856
|
my $lists = $self->lists; |
65
|
|
|
|
|
|
|
OUTER: |
66
|
100003
|
|
|
|
|
571236
|
while ( $num-- ) { |
67
|
|
|
|
|
|
|
|
68
|
100005
|
|
|
|
|
244903
|
Dumper $lists; |
69
|
|
|
|
|
|
|
# mysterious hack |
70
|
|
|
|
|
|
|
# If there is not this, I can't pass the test code. |
71
|
|
|
|
|
|
|
|
72
|
100005
|
|
|
|
|
6981974
|
my $n = int( rand( $self->available ) ) + 1; |
73
|
100005
|
|
|
|
|
674791
|
debug("-----------------------"); |
74
|
100005
|
|
|
|
|
224268
|
debug("NUM: $num"); |
75
|
100005
|
|
|
|
|
253675
|
debug("RANDOM: $n"); |
76
|
100005
|
|
|
|
|
248200
|
debug( "BEFORE: " . Dumper($lists) ); |
77
|
100005
|
|
|
|
|
967006
|
while ( my ( $item, $weight ) = each %$lists ) { |
78
|
299334
|
100
|
66
|
|
|
1181993
|
if ( $weight > 0 && $weight >= $n ) { |
79
|
100005
|
|
|
|
|
131605
|
push @ret, $item; |
80
|
100005
|
|
|
|
|
241575
|
debug("HIT: $item"); |
81
|
100005
|
100
|
|
|
|
192943
|
if ($remove) { |
82
|
100004
|
|
|
|
|
153953
|
delete $lists->{$item}; |
83
|
100004
|
|
|
|
|
310886
|
$self->available( $self->available - $weight ); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
else { |
86
|
1
|
|
|
|
|
2
|
$lists->{$item}--; |
87
|
1
|
|
|
|
|
6
|
$self->available( $self->available - 1 ); |
88
|
|
|
|
|
|
|
} |
89
|
100005
|
|
|
|
|
930215
|
debug( "AFTER: " . Dumper($lists) ); |
90
|
100005
|
|
|
|
|
989633
|
next OUTER; |
91
|
|
|
|
|
|
|
} |
92
|
199329
|
|
|
|
|
637289
|
$n -= $weight; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
100003
|
|
|
|
|
282377
|
debug( "RETURN: " . join( ",", @ret ) ); |
96
|
100003
|
|
|
|
|
352734
|
return @ret; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub left_items { |
100
|
2
|
|
|
2
|
1
|
9
|
my $self = shift; |
101
|
2
|
|
|
|
|
4
|
my @items = keys %{ $self->lists }; |
|
2
|
|
|
|
|
16
|
|
102
|
2
|
|
|
|
|
18
|
return @items; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub left_item_waits { |
106
|
2
|
|
|
2
|
1
|
15
|
my $self = shift; |
107
|
2
|
|
|
|
|
4
|
my $item = shift; |
108
|
2
|
|
|
|
|
9
|
return $self->lists->{$item}; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
__END__ |