Notice: This question originally had people write comments with a shorter program, rather than new answers. This has been changed so that people with shorter programs can get reputation too. Hopefully this doesn't become unmanageable...
There have been a couple of OEIS-related questions recently, so here's another:
Pick a sequence from the Online Encyclopedia of Integer Sequences, and write a full program or function which computes the sequence in one of the following ways:
- It prints every term in the sequence in order
- It takes an index in the sequence as input, and returns/outputs the term at that index.
You will be trying to pick the sequence with the longest possible shortest possible program/function to compute that sequence (see the example below if that's confusing). You must include which sequence you are using in your answer.
Try to make your program/function as short as possible. If anyone can find a shorter program which computes the same sequence, they should add a another answer with their shorter program. If you do find a shorter program than someone else, you should refer to their answer in yours. For all answers, a Try it Online link would be nice. If someone else has written a shorter program than yours, it would be nice if you put a link to it in your answer.
Of course, none of the programs should access the internet or the OEIS in any way, and they should all theoretically work on arbitrarily large inputs (you can ignore things like the maximum size of an integer type).
The sequence with the longest shortest program in bytes is the winner.
For example,
Let's say I pick the sequence A000027, the positive integers, and I submit this answer:
Python, 49 bytes, A000027
x = "o"
while True:
print len(x)
x += "o"
Obviously this is not a very short program for computing that sequence, so someone else (let's call them foo) might come along and add this answer:
Haskell, 2 bytes, A000027:
id
(id
is the identity function, so it will just return whatever you pass into it, and because the n
th positive integer is just n
, it will compute that sequence).
Then, the person who posted the Python solution should edit their answer:
Python, 49 bytes, A000027
Superseded by foo's answer (link).
x = "o"
while True:
print len(x)
x += "o"
As long as no one else finds a shorter program, this sequence would get a score of 2
(because id
is two bytes), and the sequence with the highest score wins.
Current best sequence: A014715, 252 bytes