We've had Meta Regex Golf and Display OEIS Sequences. Now, it is time for Meta OEIS Golf.
Challenge
Given a sequence of integers, your program/function should output a program/function in the same language that then outputs the same sequence.
A simple example in Python would be
def f(sequence):
# generate a dictionary/table lookup
dc = {index: element for (index, element) in enumerate(sequence)}
s = "lambda n: " + repr(dc) + "[n]"
# at this point, eval(s) gives a lambda function, so
# eval(s)(n) = sequence[n] = n-th element of sequence
# as required
return s
The function f
takes as input a sequence of integers and outputs the source code to a lambda
function. When the lambda
function is called on an index n
, it outputs the n
-th element of that sequence.
Output
The program that is output should be able to be submitted as an entry on this site for a code-golfsequence challenge. Hence, it could be a program or function and can use one of the following input/output methods (from the sequence tag):
- Indexing: Allowed are both 0- and 1-based indexing, and the following rules can be applied with both these types of indexing.
- Output:
- Given some index n it can return the n-th entry of the list.
- Given some index n it can return all entries up to the nth one in the sequence.
- Without taking any index, it can return a (potentially infinite) lazy list or generator that represents the whole sequence.
Behavior past the final given term in the sequence is undefined. For example, your program may be given A000004 as
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
This consists of 101 0
s. The generated program must then output 0
for each n
from 1
to 101
(assuming 1-indexing), but it can output anything (even a string or non-integer) for n=102
and onward. Consequently, the generated program can output an infinite generator, as long as the first 101 terms are right.
Scoring
Your score will be the sum of your program's length and the length of all 100 programs it generates from the A000001 to A000100 sequences (the program does not necessarily have to work for other sequences). This file has sequence A000001 on line 6, A000002 on line 7, in order up to A000100 on line 105, so each sequence is one line. The sequences have varying number of terms; for example, A000066 (line 71) only has 10 terms.
The ungolfed Python example above would score 46713 + 261 = 46974 points.
If the program outputs an auxiliary file (I'm not sure how this could help, but it might come into play), then follow the part of this ruling before the horizontal line.
Lowest score wins, as usual.