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
|
|
7406
|
use 5.004; |
|
2
|
|
|
|
|
5
|
|
20
|
2
|
|
|
2
|
|
8
|
use strict; |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
42
|
|
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
2
|
|
6
|
use vars '$VERSION', '@ISA'; |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
121
|
|
23
|
|
|
|
|
|
|
$VERSION = 72; |
24
|
2
|
|
|
2
|
|
364
|
use Math::NumSeq; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
105
|
|
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
|
|
9
|
use constant description => Math::NumSeq::__('The even integers 0, 2, 4, 6, 8, 10, etc.'); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
6
|
|
33
|
2
|
|
|
2
|
|
6
|
use constant i_start => 0; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
75
|
|
34
|
2
|
|
|
2
|
|
6
|
use constant values_min => 0; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
73
|
|
35
|
2
|
|
|
2
|
|
6
|
use constant characteristic_increasing => 1; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
59
|
|
36
|
2
|
|
|
2
|
|
6
|
use constant characteristic_integer => 1; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
77
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# cf A007958 even with at least one odd digit |
39
|
2
|
|
|
2
|
|
6
|
use constant oeis_anum => 'A005843'; # even 0,2,4 |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
630
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub rewind { |
42
|
7
|
|
|
7
|
1
|
368
|
my ($self) = @_; |
43
|
7
|
|
|
|
|
27
|
$self->{'i'} = $self->i_start; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
sub seek_to_i { |
46
|
22
|
|
|
22
|
1
|
78
|
my ($self, $i) = @_; |
47
|
22
|
|
|
|
|
31
|
$self->{'i'} = $i; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
sub seek_to_value { |
50
|
15
|
|
|
15
|
1
|
1716
|
my ($self, $value) = @_; |
51
|
15
|
|
|
|
|
25
|
$self->seek_to_i($self->value_to_i_ceil($value)); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
sub next { |
54
|
57
|
|
|
57
|
1
|
528
|
my ($self) = @_; |
55
|
57
|
|
|
|
|
43
|
my $i = $self->{'i'}++; |
56
|
57
|
|
|
|
|
61
|
return ($i, 2*$i); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
sub ith { |
59
|
24
|
|
|
24
|
1
|
34
|
my ($self, $i) = @_; |
60
|
24
|
|
|
|
|
30
|
return 2*$i; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
sub pred { |
63
|
32
|
|
|
32
|
1
|
107
|
my ($self, $value) = @_; |
64
|
|
|
|
|
|
|
### Even pred(): $value |
65
|
32
|
|
100
|
|
|
81
|
return ($value == int($value) |
66
|
|
|
|
|
|
|
&& ($value % 2) == 0); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub value_to_i { |
70
|
38
|
|
|
38
|
1
|
75
|
my ($self, $value) = @_; |
71
|
38
|
|
|
|
|
44
|
my $int = int($value); |
72
|
38
|
100
|
100
|
|
|
149
|
if ($value == $int |
73
|
|
|
|
|
|
|
&& ($int % 2) == 0) { |
74
|
15
|
|
|
|
|
1269
|
return $int/2; |
75
|
|
|
|
|
|
|
} |
76
|
23
|
|
|
|
|
22
|
return undef; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
sub value_to_i_floor { |
79
|
66
|
|
|
66
|
1
|
128
|
my ($self, $value) = @_; |
80
|
66
|
100
|
|
|
|
91
|
if ($value < 0) { |
81
|
14
|
|
|
|
|
21
|
my $i = int($value/2); |
82
|
14
|
100
|
|
|
|
21
|
if (2*$i == $value) { |
83
|
3
|
|
|
|
|
8
|
return $i; |
84
|
|
|
|
|
|
|
} else { |
85
|
11
|
|
|
|
|
28
|
return $i-1; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} else { |
88
|
52
|
|
|
|
|
613
|
return int($value/2); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
sub value_to_i_ceil { |
92
|
76
|
|
|
76
|
1
|
117
|
my ($self, $value) = @_; |
93
|
76
|
|
|
|
|
113
|
my $i = int($value/2); |
94
|
76
|
100
|
|
|
|
813
|
if (2*$i < $value) { |
95
|
24
|
|
|
|
|
46
|
return $i+1; |
96
|
|
|
|
|
|
|
} else { |
97
|
52
|
|
|
|
|
793
|
return $i; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
sub value_to_i_estimate { |
101
|
16
|
|
|
16
|
1
|
297
|
my ($self, $value) = @_; |
102
|
16
|
|
|
|
|
16
|
return int($value/2); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |
106
|
|
|
|
|
|
|
__END__ |