Your task, if you choose to accept it, is simple.


You must make a program that, when run, prints some (as many as you want) terms in a sequence that you choose. The sequence must be a valid OEIS sequence. The twist is that when you take the characters from your code that make up your sequence, string them together and run them in the same language, you should get the formula for the nth of your sequence for your sequence.


Let's say I made this program:


and chose the sequence of squares: http://oeis.org/A000290

and I chose it to print the first 5 terms of the sequence, the output should be:

1, 4, 9, 16, 25

Note: the output is flexible, you can choose what delimiter you want separating the terms, but the delimiter should be noticeable so that each of the terms of the sequence can be differentiated.

Now, the character at index 1 is a. The character at index 4 is d. The character at index 9 is i. So my new program would be:


and it would have to print the formula for the nth term for my sequence, which is:



Other things

  • You must print a minimum of 5 terms.
  • You may choose to 0- or 1-index.
  • Repeated numbers means repeated characters.
  • If your sequence isn't in order (e.g. it goes backwards), then your code still follows it (e.g. your code is written backwards).
  • You must use and only use the numbers in bounds of your answer, even if it has already gone out of bounds. You cannot use numbers from the same sequence you did not print.
  • If your sequence does not officially have a formula, you may use the first 3 letters of the name stated on the OEIS website (e.g. the fibonacci sequence would print fib and the lucas-lehmer sequence would print luc).

Remember, this is , so shortest answer, in bytes, wins!

  • \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$ – Martin Ender Nov 23 '16 at 18:15
  • \$\begingroup\$ Must the variable name be n? \$\endgroup\$ – ETHproductions Nov 23 '16 at 18:19
  • \$\begingroup\$ I'm putting this on hold until a few more details about the challenge are sorted out (see the chatroom linked above). \$\endgroup\$ – Martin Ender Nov 23 '16 at 18:30
  • 5
    \$\begingroup\$ To people already casting reopen votes. If one answer assumes that you should take as many values from the sequence as possible, and another answer assumes that you only take as many as you've printed in the full program, then the challenge is unclear and needs to be improved before adding even more answers. Plus, this is not the only edge case that isn't addressed yet (how should non-increasing sequences, or sequences with repeated values be handled?). \$\endgroup\$ – Martin Ender Nov 23 '16 at 18:45
  • \$\begingroup\$ I absolutely love this challenge, but it should be a contest to see who can use the most complex formula. \$\endgroup\$ – Magic Octopus Urn Nov 23 '16 at 19:09

10 Answers 10


05AB1E, 10 bytes, A008585

This code outputs the first 11 elements of the sequence 3n.

3TÝ' §n*»J

Try it online!


3            # push 3
             # STACK: 3
 TÝ          # push range [0 ... 10]
             # STACK: 3, [0,1,2,3,4,5,6,7,8,9,10]
   ' §       # push a space char converted to string
             # STACK: 3, [0,1,2,3,4,5,6,7,8,9,10], " "
      n      # square the string
             # STACK: 3, [0,1,2,3,4,5,6,7,8,9,10]
       *     # multiply the top 2 elements of the stack
             # STACK: [0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30]
        »    # join by newlines
         J   # join to string

Taking every nth item (0-indexed) gives:


which outputs 3n


Python 2, 35 Bytes

I decided to use the obvious sequence A000027, which essentially has the formula n ;) If you run the following code:

exec'print n;n+=1;'*8

You get the output:


And if you take the 8 characters from my source code (0-indexed), you get this:


Which simply prints n.

If you were hoping for a more exciting answer, here's a Python 2 solution for n^2, i.e. A000290:

#p  r    i      n        t          '            n              ^                2                  '
exec'print n*n;n+=1;'*10

05AB1E, 7 6 bytes, A000027

5L'n s

Try it online!


5L      # Push [1, 2, 3, 4, 5]
  'n    # Push "n"
        # Do nothing
     s  # Swap (only in original program)
        # Implicit print
  • \$\begingroup\$ 4L"n"s is also an option, or am I way off base here? \$\endgroup\$ – Magic Octopus Urn Nov 23 '16 at 18:38
  • \$\begingroup\$ Yes it is. But it needs to be 5 not 4 \$\endgroup\$ – Oliver Ni Nov 23 '16 at 18:39
  • \$\begingroup\$ "and I chose it to print the first 5 terms of the sequence" - OP \$\endgroup\$ – Magic Octopus Urn Nov 23 '16 at 18:40
  • 1
    \$\begingroup\$ @carusocomputing Look on the bottom \$\endgroup\$ – Oliver Ni Nov 23 '16 at 18:42

Octave, 64 bytes A000290

I went for the n^2 one:

@()(1:5 ).^2 % '        n          ^            2              '

Take the terms 1, 4, 9, 16, 25, 36, 49 and 64 to get:


which prints:


05AB1E, 30 28 bytes, A000290

This is the sequence of squares

"  n    ^      2        "5Ln

Outputs the first 5 terms of the sequence with the formula n^2:

[1, 4, 9, 16, 25]

Try it online!

This is 1-indexed. So taking the characters from the code that make up the sequence, I get


Which outputs


Try it online!


"  n    ^      2        "              # push this string
                         5             # push 5
                          L            # push range [1, ..., 5]
                            n          # square it
                                       # implicit output

Wonder, 16 bytes A005843

 0";2"tk 5gen *2

This was once DASH, but has now been renamed to Wonder.

Outputs the first 6 even numbers. Note the leading space. Keeping the indices 0, 2, 4, 6, and 8 yields:


Which prints 2t.



This is just a string and a number.

tk 5gen *2

This generates an infinite list of even numbers starting from 0, then takes the first 5 items from that list.


MATL, 8 bytes, A000027

Thanks to Oliver for a correction interpreting the challenge

'n'  5:&

The code prints 1 2 3 4 5. Keeping only the first give chars it prints n.

Try it online!


Octave, 49 bytes, A109234

@()  1      :      5     %'floor (n*sin h(1)) ';]

The sequence floor(n*sinh(1)) are all numbers from 1 and up, except 6, 13, 20, 26, 33, 40, 46, _3, _0, _6 ... So, the characters used to make 1 2 3 4 5 must be placed in those positions. The remaining positions are used for the string explaining the function.


05AB1E, 15 bytes, A001477

"n-1"     žhSðý

Uses the CP-1252 encoding. Try it online!


Haystack, 21 10 9 Bytes

Haystack has had a lot of new features added in the past few days :) Of course, I am going to use A000027. Here's the inital program:


This will print out:

[1, 2, 3, 4, 5]

And if you take the characters 1-5, 0-indexed, you get:


Which prints n.

If you want to have some more fun, here's a solution for A000290:


If you want to see only the necessary chars, click here.

This will print the first 7 squares, and their corresponding chars in the above program, 0-indexed, are:


Which prints n^2.


Not the answer you're looking for? Browse other questions tagged or ask your own question.