# Make your program sequential! [closed]

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

# Objective

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.

# Example

Let's say I made this program:

abcdefghij


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:

adi


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

n^2


Simple!

## 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!

## closed as unclear what you're asking by Martin EnderNov 23 '16 at 18:30

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• Comments are not for extended discussion; this conversation has been moved to chat. – Martin Ender Nov 23 '16 at 18:15
• Must the variable name be n? – ETHproductions Nov 23 '16 at 18:19
• I'm putting this on hold until a few more details about the challenge are sorted out (see the chatroom linked above). – Martin Ender Nov 23 '16 at 18:30
• 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?). – Martin Ender Nov 23 '16 at 18:45
• I absolutely love this challenge, but it should be a contest to see who can use the most complex formula. – Magic Octopus Urn Nov 23 '16 at 19:09

# 05AB1E, 10 bytes, A008585

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

3TÝ' §n*»J


Try it online!

Explanation

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:

3'nJ


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:

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


You get the output:

1
2
3
4
5
6
7
8


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

print'n'


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                  '
n=1
exec'print n*n;n+=1;'*10


# 05AB1E, 7 6 bytes, A000027

5L'n s


Try it online!

Explanation:

5L      # Push [1, 2, 3, 4, 5]
'n    # Push "n"
# Do nothing
s  # Swap (only in original program)
# Implicit print

• 4L"n"s is also an option, or am I way off base here? – Magic Octopus Urn Nov 23 '16 at 18:38
• Yes it is. But it needs to be 5 not 4 – Oliver Ni Nov 23 '16 at 18:39
• "and I chose it to print the first 5 terms of the sequence" - OP – Magic Octopus Urn Nov 23 '16 at 18:40
• @carusocomputing Look on the bottom – 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:

@()'n^2'


which prints:

n^2


# 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

"n^2"


Which outputs

n^2


Try it online!

### Explanation

"  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:

 "2t


Which prints 2t.

# Explanation

0";2"


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, 2110 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:

<"n"o|OR4


This will print out:

[1, 2, 3, 4, 5]


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

"n"o|


Which prints n.

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

^"_(n\D2l^
3keU02/:[W
D5m"5s\ih_
Cr:OF]uAIe
hWd>g|AkuH
/6R>ud*O,\
)G:q\$n|4y{
:|v\X:?dP/


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:

"n^2"O|


Which prints n^2.