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
|
|
7472
|
use 5.004; |
|
2
|
|
|
|
|
5
|
|
20
|
2
|
|
|
2
|
|
7
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
52
|
|
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
2
|
|
9
|
use vars '$VERSION', '@ISA'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
123
|
|
23
|
|
|
|
|
|
|
$VERSION = 72; |
24
|
2
|
|
|
2
|
|
365
|
use Math::NumSeq; |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
62
|
|
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
|
|
9
|
use constant description => Math::NumSeq::__('The odd integers 1, 3, 5, 7, 9, etc, 2i+1.'); |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
5
|
|
33
|
2
|
|
|
2
|
|
7
|
use constant values_min => 1; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
68
|
|
34
|
2
|
|
|
2
|
|
7
|
use constant default_i_start => 0; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
70
|
|
35
|
2
|
|
|
2
|
|
5
|
use constant characteristic_increasing => 1; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
61
|
|
36
|
2
|
|
|
2
|
|
6
|
use constant characteristic_integer => 1; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
67
|
|
37
|
2
|
|
|
2
|
|
6
|
use constant oeis_anum => 'A005408'; # odd 1,3,5,... |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
641
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub rewind { |
40
|
7
|
|
|
7
|
1
|
367
|
my ($self) = @_; |
41
|
7
|
|
|
|
|
20
|
$self->{'i'} = $self->i_start; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
sub seek_to_i { |
44
|
22
|
|
|
22
|
1
|
79
|
my ($self, $i) = @_; |
45
|
22
|
|
|
|
|
26
|
$self->{'i'} = $i; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
sub seek_to_value { |
48
|
15
|
|
|
15
|
1
|
358
|
my ($self, $value) = @_; |
49
|
15
|
|
|
|
|
19
|
$self->seek_to_i($self->value_to_i_ceil($value)); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
sub next { |
52
|
57
|
|
|
57
|
1
|
508
|
my ($self) = @_; |
53
|
57
|
|
|
|
|
40
|
my $i = $self->{'i'}++; |
54
|
57
|
|
|
|
|
66
|
return ($i, 2*$i+1); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
sub ith { |
57
|
24
|
|
|
24
|
1
|
39
|
my ($self, $i) = @_; |
58
|
24
|
|
|
|
|
29
|
return 2*$i+1; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
sub pred { |
61
|
32
|
|
|
32
|
1
|
116
|
my ($self, $value) = @_; |
62
|
|
|
|
|
|
|
### Odd pred(): $value |
63
|
32
|
|
100
|
|
|
69
|
return ($value == int($value) |
64
|
|
|
|
|
|
|
&& ($value % 2)); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub value_to_i { |
68
|
38
|
|
|
38
|
1
|
85
|
my ($self, $value) = @_; |
69
|
38
|
|
|
|
|
41
|
my $int = int($value); |
70
|
38
|
100
|
100
|
|
|
156
|
if ($value == $int |
71
|
|
|
|
|
|
|
&& ($int % 2) == 1) { |
72
|
15
|
|
|
|
|
1070
|
return ($int-1)/2; |
73
|
|
|
|
|
|
|
} |
74
|
23
|
|
|
|
|
24
|
return undef; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
sub value_to_i_floor { |
77
|
66
|
|
|
66
|
1
|
119
|
my ($self, $value) = @_; |
78
|
66
|
100
|
|
|
|
89
|
if (($value -= 1) < 0) { |
79
|
17
|
|
|
|
|
20
|
my $i = int($value/2); |
80
|
17
|
100
|
|
|
|
22
|
if (2*$i > $value) { |
81
|
14
|
|
|
|
|
23
|
return $i-1; |
82
|
|
|
|
|
|
|
} else { |
83
|
3
|
|
|
|
|
7
|
return $i; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} else { |
86
|
49
|
|
|
|
|
1321
|
return int($value/2); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
sub value_to_i_ceil { |
90
|
77
|
|
|
77
|
1
|
115
|
my ($self, $value) = @_; |
91
|
77
|
|
|
|
|
95
|
$value -= 1; |
92
|
77
|
|
|
|
|
791
|
my $i = int($value/2); |
93
|
77
|
100
|
|
|
|
738
|
if (2*$i < $value) { |
94
|
23
|
|
|
|
|
34
|
return $i+1; |
95
|
|
|
|
|
|
|
} else { |
96
|
54
|
|
|
|
|
718
|
return $i; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
sub value_to_i_estimate { |
100
|
16
|
|
|
16
|
1
|
378
|
my ($self, $value) = @_; |
101
|
16
|
|
|
|
|
17
|
return int(($value-1)/2); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
105
|
|
|
|
|
|
|
__END__ |