Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re^3: Numerically generate the perl sequence 1, 11, 111, ....

by moritz (Cardinal)
on Oct 12, 2008 at 14:48 UTC ( #716680=note: print w/replies, xml ) Need Help??

in reply to Re^2: Numerically generate the perl sequence 1, 11, 111, ....
in thread Generate the perl sequence 1, 11, 111, ....

It shouldn't be too hard to make this work.

By simply looking at the sequence of the pair-wise difference and ratio and correlating them to the original sequence or a constant, you can get good guesses for most commonly used sequences, if you just allow a few levels of recursion:

1, 2, 3, 4, 5 differences 1, 1, 1, 1 # constant 1, 2, 4, 8, 16 ratios: 2, 2, 2, 2 # constant 1, 2, 3, 5, 8 differences: 1, 2, 3, 5 # sames as original shifted by one 1, 11, 111, 1111, 11111 differences: 10, 100, 1000, 10000 ratios: 10, 10, 10 # constant

The fibonacci sequence is the only one example that needs autocorrelating. Other ones that could use the autocorrelation are -1, 1, -1, 1, ... and 0, 1, 0, 1, ....

In case of ambiguousness the solution with the shallowest recursion would win.

I'll try to come up with a prototype implementation that can be used as basis for a specification. But it won't be this or the next week, so have a little patience ;)

Ideally there would be some sub or method that can be overridden to detect sequences if the built-in mechanism fails..

Replies are listed 'Best First'.
Re^4: Numerically generate the perl sequence 1, 11, 111, ....
by JavaFan (Canon) on Oct 12, 2008 at 15:41 UTC
    One interesting and useful sequence that springs to mind is:
    2, 3, 5, 7, 11, 13, ... # Prime numbers.
    but with neither differences, nor ratios could one continue the sequence.
      ... nor can it be efficiently computed, which is why I'd leave it out.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://716680]
[hippo]: Other package managers are available
LanX wouldn't update system Perl!
[Discipulus]: prathap keerthipati might be it is better to install an alternative Perl instead and do not touch the system one
[LanX]: see perlbrew for alternative Perl installations
[marto]: unless you know exactly what you're doing an often saner option is to simply build another Perl rather than replace the system one

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (14)
As of 2017-03-23 10:40 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (285 votes). Check out past polls.