Math::NumSeq::AsciiSelf -- sequence is its own ASCII digits
use Math::NumSeq::AsciiSelf; my $seq = Math::NumSeq::AsciiSelf->new; my ($i, $value) = $seq->next;
A sequence which is itself in ASCII, Sloane's OEIS A109733.
53, 51, 53, 49, 53, 51, 52, 57, etc
The first value 53 is digits 5,3 which in ASCII is the initial 53 and append 51. That new 51 is digits 5,1 which is ASCII 53 and 49 which are appended. Then those new digits 5,3,4,9 are ASCII 53,51,52,57 which are appended, and so on.
Notice that interpreting the sequence values as ASCII gives the digits of the sequence itself, and conversely expanding each value to its digits represented in ASCII leaves the sequence unchanged.
The default is digits in decimal. There's an experimental mostly-working
radix parameter to do it in other bases. Bases 8, 12 and 16 end up as repetitions of a single value, which is not very interesting. Bases 5, 9 and 13 have a choice of two starting self-ASCII values, but only the smallest is used for now. Base 7
ith() is wrong, but <next()> is right.
See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence classes.
$seq = Math::NumSeq::AsciiSelf->new ()
Create and return a new sequence object.
$value = $seq->ith($i)
$i'th member of the sequence. The first is i=1.
The doubling described above is the key to the sequence structure. Numbering from k=i-1 so k=0 is the first member, take the bits of k from high to low. Start with value 53. At each bit expand the value to its digits in ASCII so for example 53 -> 53,51. Take the first or second according to whether the bit from k is 0 or 1.
The bits of k for the ith calculation can be retained and incremented by a carry algorithm, rather than breaking down in each
next() call. The two expanded ASCII values can be kept at each bit and selected by the bit value.
With the experimental
radix parameter for base 6 and smaller the ASCII expands to 3 or more values. For example 48 in binary is 110000 so six ASCII 49,49,48,48,48,48. The calculations are the same, but digits of that size rather than bits.
In base 7 the digit lengths vary, since 48=66 and 49=100, so for it the digit range depends on the expansion. That's fine for
next() where the number of digits at each state is available, but how best might
ith() notice the shorter count for zeros?
ith() gives wrong values for the experimental
radix parameter for radix 7.
can('ith') returns false for that radix, as a way of saying
ith() is not available. (Other bases are ok.)
Copyright 2011, 2012, 2013, 2014 Kevin Ryde
Math-NumSeq is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Math-NumSeq is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Math-NumSeq. If not, see <http://www.gnu.org/licenses/>.