line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright 2010, 2011, 2012, 2013, 2014 Kevin Ryde |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# This file is part of Math-NumSeq. |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# Math-NumSeq is free software; you can redistribute it and/or modify |
6
|
|
|
|
|
|
|
# it under the terms of the GNU General Public License as published by the |
7
|
|
|
|
|
|
|
# Free Software Foundation; either version 3, or (at your option) any later |
8
|
|
|
|
|
|
|
# version. |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# Math-NumSeq is distributed in the hope that it will be useful, but |
11
|
|
|
|
|
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
12
|
|
|
|
|
|
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
13
|
|
|
|
|
|
|
# for more details. |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License along |
16
|
|
|
|
|
|
|
# with Math-NumSeq. If not, see . |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
package Math::NumSeq::Even; |
19
|
2
|
|
|
2
|
|
14219
|
use 5.004; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
81
|
|
20
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
71
|
|
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
2
|
|
10
|
use vars '$VERSION', '@ISA'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
122
|
|
23
|
|
|
|
|
|
|
$VERSION = 71; |
24
|
2
|
|
|
2
|
|
623
|
use Math::NumSeq; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
93
|
|
25
|
|
|
|
|
|
|
@ISA = ('Math::NumSeq'); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# uncomment this to run the ### lines |
29
|
|
|
|
|
|
|
#use Smart::Comments; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# use constant name => Math::NumSeq::__('Even Integers'); |
32
|
2
|
|
|
2
|
|
10
|
use constant description => Math::NumSeq::__('The even integers 0, 2, 4, 6, 8, 10, etc.'); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
10
|
|
33
|
2
|
|
|
2
|
|
11
|
use constant i_start => 0; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
97
|
|
34
|
2
|
|
|
2
|
|
11
|
use constant values_min => 0; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
93
|
|
35
|
2
|
|
|
2
|
|
12
|
use constant characteristic_increasing => 1; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
92
|
|
36
|
2
|
|
|
2
|
|
12
|
use constant characteristic_integer => 1; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
91
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# cf A007958 even with at least one odd digit |
39
|
2
|
|
|
2
|
|
11
|
use constant oeis_anum => 'A005843'; # even 0,2,4 |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
1073
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub rewind { |
42
|
7
|
|
|
7
|
1
|
488
|
my ($self) = @_; |
43
|
7
|
|
|
|
|
47
|
$self->{'i'} = $self->i_start; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
sub seek_to_i { |
46
|
22
|
|
|
22
|
1
|
145
|
my ($self, $i) = @_; |
47
|
22
|
|
|
|
|
52
|
$self->{'i'} = $i; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
sub seek_to_value { |
50
|
15
|
|
|
15
|
1
|
2476
|
my ($self, $value) = @_; |
51
|
15
|
|
|
|
|
37
|
$self->seek_to_i($self->value_to_i_ceil($value)); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
sub next { |
54
|
57
|
|
|
57
|
1
|
875
|
my ($self) = @_; |
55
|
57
|
|
|
|
|
80
|
my $i = $self->{'i'}++; |
56
|
57
|
|
|
|
|
132
|
return ($i, 2*$i); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
sub ith { |
59
|
24
|
|
|
24
|
1
|
70
|
my ($self, $i) = @_; |
60
|
24
|
|
|
|
|
61
|
return 2*$i; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
sub pred { |
63
|
32
|
|
|
32
|
1
|
182
|
my ($self, $value) = @_; |
64
|
|
|
|
|
|
|
### Even pred(): $value |
65
|
32
|
|
100
|
|
|
138
|
return ($value == int($value) |
66
|
|
|
|
|
|
|
&& ($value % 2) == 0); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub value_to_i { |
70
|
38
|
|
|
38
|
1
|
146
|
my ($self, $value) = @_; |
71
|
38
|
|
|
|
|
190
|
my $int = int($value); |
72
|
38
|
100
|
100
|
|
|
244
|
if ($value == $int |
73
|
|
|
|
|
|
|
&& ($int % 2) == 0) { |
74
|
15
|
|
|
|
|
1927
|
return $int/2; |
75
|
|
|
|
|
|
|
} |
76
|
23
|
|
|
|
|
47
|
return undef; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
sub value_to_i_floor { |
79
|
66
|
|
|
66
|
1
|
215
|
my ($self, $value) = @_; |
80
|
66
|
100
|
|
|
|
134
|
if ($value < 0) { |
81
|
14
|
|
|
|
|
25
|
my $i = int($value/2); |
82
|
14
|
100
|
|
|
|
33
|
if (2*$i == $value) { |
83
|
3
|
|
|
|
|
10
|
return $i; |
84
|
|
|
|
|
|
|
} else { |
85
|
11
|
|
|
|
|
48
|
return $i-1; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} else { |
88
|
52
|
|
|
|
|
908
|
return int($value/2); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
sub value_to_i_ceil { |
92
|
76
|
|
|
76
|
1
|
233
|
my ($self, $value) = @_; |
93
|
76
|
|
|
|
|
133
|
my $i = int($value/2); |
94
|
76
|
100
|
|
|
|
1113
|
if (2*$i < $value) { |
95
|
24
|
|
|
|
|
72
|
return $i+1; |
96
|
|
|
|
|
|
|
} else { |
97
|
52
|
|
|
|
|
1133
|
return $i; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
sub value_to_i_estimate { |
101
|
16
|
|
|
16
|
1
|
488
|
my ($self, $value) = @_; |
102
|
16
|
|
|
|
|
36
|
return int($value/2); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |
106
|
|
|
|
|
|
|
__END__ |