line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Number::Natural::SetTheory; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
130099
|
use 5.010; |
|
5
|
|
|
|
|
19
|
|
|
5
|
|
|
|
|
192
|
|
4
|
5
|
|
|
5
|
|
5421
|
use boolean; |
|
5
|
|
|
|
|
24704
|
|
|
5
|
|
|
|
|
27
|
|
5
|
5
|
|
|
5
|
|
6120
|
use JSON qw/to_json/; |
|
5
|
|
|
|
|
79269
|
|
|
5
|
|
|
|
|
30
|
|
6
|
5
|
|
|
5
|
|
844
|
use strict; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
143
|
|
7
|
5
|
|
|
5
|
|
3517
|
use utf8; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
26
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our (@EXPORT, @EXPORT_OK, %EXPORT_TAGS); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
BEGIN |
12
|
|
|
|
|
|
|
{ |
13
|
5
|
|
|
5
|
|
10
|
$Number::Natural::SetTheory::AUTHORITY = 'cpan:TOBYINK'; |
14
|
5
|
|
|
|
|
10
|
$Number::Natural::SetTheory::VERSION = '0.003'; |
15
|
|
|
|
|
|
|
|
16
|
5
|
|
|
|
|
10
|
@EXPORT = qw/ /; |
17
|
5
|
|
|
|
|
11
|
@EXPORT_OK = qw/ set_is_number set_to_number number_to_set set_to_string /; |
18
|
5
|
|
|
|
|
15
|
$EXPORT_TAGS{'all'} = \@EXPORT_OK; |
19
|
5
|
|
|
|
|
104
|
$EXPORT_TAGS{'default'} = $EXPORT_TAGS{'standard'} = \@EXPORT; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
5
|
|
|
5
|
|
28
|
use base qw/Exporter/; |
|
5
|
|
|
|
|
43
|
|
|
5
|
|
|
|
|
3322
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub set_is_number |
25
|
|
|
|
|
|
|
{ |
26
|
80
|
|
|
80
|
1
|
4475
|
my ($set, $number) = @_; |
27
|
80
|
50
|
|
|
|
162
|
return undef unless int($number)==$number; |
28
|
|
|
|
|
|
|
|
29
|
80
|
0
|
33
|
|
|
199
|
if (!ref $set and $set =~ /^\d+$/ and int($set)==$set) |
|
|
|
33
|
|
|
|
|
30
|
|
|
|
|
|
|
{ |
31
|
0
|
0
|
|
|
|
0
|
return ($set==$number) ? true : false; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
80
|
50
|
|
|
|
164
|
return undef unless ref $set eq 'ARRAY'; |
35
|
|
|
|
|
|
|
|
36
|
80
|
|
|
|
|
98
|
my $count = scalar @$set; |
37
|
|
|
|
|
|
|
|
38
|
80
|
100
|
|
|
|
147
|
return false |
39
|
|
|
|
|
|
|
if ($count != $number); |
40
|
|
|
|
|
|
|
|
41
|
79
|
100
|
|
|
|
193
|
return true |
42
|
|
|
|
|
|
|
if ($count == 0); |
43
|
|
|
|
|
|
|
|
44
|
39
|
|
|
|
|
75
|
my %accounted_for = map { $_ => false } 0..($count - 1); |
|
65
|
|
|
|
|
191
|
|
45
|
|
|
|
|
|
|
|
46
|
39
|
|
|
|
|
257
|
foreach my $member (@$set) |
47
|
|
|
|
|
|
|
{ |
48
|
65
|
|
|
|
|
189
|
my $number = set_to_number($member); |
49
|
|
|
|
|
|
|
|
50
|
65
|
100
|
66
|
|
|
342
|
if (defined $number and exists $accounted_for{$number}) |
51
|
|
|
|
|
|
|
{ |
52
|
64
|
50
|
|
|
|
157
|
if ($accounted_for{$number}) |
|
|
50
|
|
|
|
|
|
53
|
|
|
|
|
|
|
{ |
54
|
0
|
|
|
|
|
0
|
return false; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
elsif (not $accounted_for{$number}) |
57
|
|
|
|
|
|
|
{ |
58
|
64
|
|
|
|
|
902
|
$accounted_for{$number} = true; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
39
|
100
|
|
|
|
251
|
if (grep { !$_ } values %accounted_for) |
|
65
|
|
|
|
|
264
|
|
64
|
|
|
|
|
|
|
{ |
65
|
1
|
|
|
|
|
14
|
return false; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
38
|
|
|
|
|
384
|
return true; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub number_to_set |
72
|
|
|
|
|
|
|
{ |
73
|
15
|
|
|
15
|
1
|
27
|
my ($num) = @_; |
74
|
|
|
|
|
|
|
|
75
|
15
|
50
|
33
|
|
|
112
|
unless ($num =~ /^\d+$/ and int($num)==$num) |
76
|
|
|
|
|
|
|
{ |
77
|
0
|
|
|
|
|
0
|
return undef; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
15
|
100
|
|
|
|
59
|
return [] if $num==0; |
81
|
7
|
|
|
|
|
15
|
my @set = map { number_to_set($_) } 0 .. ($num-1); |
|
11
|
|
|
|
|
25
|
|
82
|
7
|
|
|
|
|
33
|
return \@set; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub set_to_number |
86
|
|
|
|
|
|
|
{ |
87
|
71
|
|
|
71
|
1
|
95
|
my ($set) = @_; |
88
|
|
|
|
|
|
|
|
89
|
71
|
50
|
66
|
|
|
192
|
if (!ref $set and $set =~ /^\d+$/ and int($set)==$set) |
|
|
|
33
|
|
|
|
|
90
|
|
|
|
|
|
|
{ |
91
|
0
|
|
|
|
|
0
|
return $set; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
71
|
100
|
|
|
|
163
|
return undef unless ref $set eq 'ARRAY'; |
95
|
|
|
|
|
|
|
|
96
|
70
|
100
|
|
|
|
141
|
if (set_is_number($set, scalar @$set)) |
97
|
|
|
|
|
|
|
{ |
98
|
69
|
|
|
|
|
805
|
return scalar @$set; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
1
|
|
|
|
|
16
|
return undef; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub set_to_string |
105
|
|
|
|
|
|
|
{ |
106
|
4
|
|
|
4
|
1
|
11
|
my ($set) = @_; |
107
|
4
|
|
|
|
|
13
|
my $string = to_json($set); |
108
|
4
|
|
|
|
|
83
|
$string =~ s/\[/\{/g; |
109
|
4
|
|
|
|
|
13
|
$string =~ s/\]/\}/g; |
110
|
4
|
|
|
|
|
16
|
return $string; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
'What exactly is zero?'; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
__END__ |