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::Odd; |
19
|
2
|
|
|
2
|
|
15013
|
use 5.004; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
85
|
|
20
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
83
|
|
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
2
|
|
12
|
use vars '$VERSION', '@ISA'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
146
|
|
23
|
|
|
|
|
|
|
$VERSION = 71; |
24
|
2
|
|
|
2
|
|
1183
|
use Math::NumSeq; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
101
|
|
25
|
|
|
|
|
|
|
@ISA = ('Math::NumSeq'); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# uncomment this to run the ### lines |
28
|
|
|
|
|
|
|
#use Smart::Comments; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# use constant name => Math::NumSeq::__('Odd Integers'); |
32
|
2
|
|
|
2
|
|
14
|
use constant description => Math::NumSeq::__('The odd integers 1, 3, 5, 7, 9, etc, 2i+1.'); |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
11
|
|
33
|
2
|
|
|
2
|
|
11
|
use constant values_min => 1; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
98
|
|
34
|
2
|
|
|
2
|
|
9
|
use constant default_i_start => 0; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
81
|
|
35
|
2
|
|
|
2
|
|
11
|
use constant characteristic_increasing => 1; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
75
|
|
36
|
2
|
|
|
2
|
|
10
|
use constant characteristic_integer => 1; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
85
|
|
37
|
2
|
|
|
2
|
|
11
|
use constant oeis_anum => 'A005408'; # odd 1,3,5,... |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
997
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub rewind { |
40
|
7
|
|
|
7
|
1
|
643
|
my ($self) = @_; |
41
|
7
|
|
|
|
|
36
|
$self->{'i'} = $self->i_start; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
sub seek_to_i { |
44
|
22
|
|
|
22
|
1
|
229
|
my ($self, $i) = @_; |
45
|
22
|
|
|
|
|
57
|
$self->{'i'} = $i; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
sub seek_to_value { |
48
|
15
|
|
|
15
|
1
|
1220
|
my ($self, $value) = @_; |
49
|
15
|
|
|
|
|
35
|
$self->seek_to_i($self->value_to_i_ceil($value)); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
sub next { |
52
|
57
|
|
|
57
|
1
|
848
|
my ($self) = @_; |
53
|
57
|
|
|
|
|
92
|
my $i = $self->{'i'}++; |
54
|
57
|
|
|
|
|
130
|
return ($i, 2*$i+1); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
sub ith { |
57
|
24
|
|
|
24
|
1
|
65
|
my ($self, $i) = @_; |
58
|
24
|
|
|
|
|
61
|
return 2*$i+1; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
sub pred { |
61
|
32
|
|
|
32
|
1
|
171
|
my ($self, $value) = @_; |
62
|
|
|
|
|
|
|
### Odd pred(): $value |
63
|
32
|
|
100
|
|
|
117
|
return ($value == int($value) |
64
|
|
|
|
|
|
|
&& ($value % 2)); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub value_to_i { |
68
|
38
|
|
|
38
|
1
|
143
|
my ($self, $value) = @_; |
69
|
38
|
|
|
|
|
65
|
my $int = int($value); |
70
|
38
|
100
|
100
|
|
|
236
|
if ($value == $int |
71
|
|
|
|
|
|
|
&& ($int % 2) == 1) { |
72
|
15
|
|
|
|
|
1628
|
return ($int-1)/2; |
73
|
|
|
|
|
|
|
} |
74
|
23
|
|
|
|
|
46
|
return undef; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
sub value_to_i_floor { |
77
|
66
|
|
|
66
|
1
|
217
|
my ($self, $value) = @_; |
78
|
66
|
100
|
|
|
|
145
|
if (($value -= 1) < 0) { |
79
|
17
|
|
|
|
|
80
|
my $i = int($value/2); |
80
|
17
|
100
|
|
|
|
41
|
if (2*$i > $value) { |
81
|
14
|
|
|
|
|
52
|
return $i-1; |
82
|
|
|
|
|
|
|
} else { |
83
|
3
|
|
|
|
|
12
|
return $i; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} else { |
86
|
49
|
|
|
|
|
2002
|
return int($value/2); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
sub value_to_i_ceil { |
90
|
77
|
|
|
77
|
1
|
215
|
my ($self, $value) = @_; |
91
|
77
|
|
|
|
|
110
|
$value -= 1; |
92
|
77
|
|
|
|
|
1196
|
my $i = int($value/2); |
93
|
77
|
100
|
|
|
|
1094
|
if (2*$i < $value) { |
94
|
23
|
|
|
|
|
73
|
return $i+1; |
95
|
|
|
|
|
|
|
} else { |
96
|
54
|
|
|
|
|
1658
|
return $i; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
sub value_to_i_estimate { |
100
|
16
|
|
|
16
|
1
|
569
|
my ($self, $value) = @_; |
101
|
16
|
|
|
|
|
36
|
return int(($value-1)/2); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
105
|
|
|
|
|
|
|
__END__ |