Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Challenge: Simple algorithm for continuing series of integers

by moritz (Cardinal)
on Oct 19, 2008 at 20:21 UTC ( [id://718084]=note: print w/replies, xml ) Need Help??


in reply to Re: Challenge: Simple algorithm for continuing series of integers
in thread Challenge: Simple algorithm for continuing series of integers

Well, your reply is interesting, but not very helpful.

Actually some time ago I used to always say "17" when somebody asked me how to continue a a given series.

So I thought about a more strict formulation of the question. I came up with something along these lines:

Given a series @a = $a[0] ... $a[$n-1], find all pure functions f($n, @a) that only uses the operators +, -, *, /, % and **, the arguments and number literals (and parenthesis for grouping), and where the following identity holds: For all $k <= $n: f($k, @a[0..$k-1]) == $a[$k].

Of all these functions, use the simplest, ie the one that uses the smallest number of operators. Then calculate the next value with that function.

Replies are listed 'Best First'.
Re^3: Challenge: Simple algorithm for continuing series of integers
by JavaFan (Canon) on Oct 19, 2008 at 21:42 UTC
    Note that for any given series of numbers a1 .. ak there's a polynomial f(x) of degree less then or equal to k-1 such that f(1) == a1, f(2) == a2, etc. For obvious reasons, all the coefficients of f(x) are rational (otherwise, f(x) cannot be an integer for integer x).

    Given that there's at least one function that uses only the given operations, and a finite number of such operations, there's also one that uses the smallest number of operators. But it's not necessarily unique.

    I don't know whether this is helpful.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://718084]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-25 06:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found