# algorithms and the sequencing of numbers given a value

The numbers in the table below are the result of executing an algorithm that has one parameter $$n$$, a non-negative integer, and produces sequences of integers as outputs. For values of $$n$$ from 0 to 5, the algorithm produces the following sequences of numbers as outputs:

• $$n = 0$$: 0, 2.
• $$n = 1$$: 3, 5, 7, 9.
• $$n = 2$$: 6, 8, 10, 12, 14, 16.
• $$n = 3$$: 9, 11, 13, 15, 17, 19, 21, 23.
• $$n = 4$$: 12, 14, 16, 18, 20, 22, 24, 26, 28, 30.
• $$n = 5$$: 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37.
• $$n = 6$$: ?

I just started a course and I don't understand. I get the pattern differences and I understand all the patterns that are formed such as each outputs first number is a multiple of three and then the lists rise by two for each output given. When I put this down off of what I was given as a reference in the class it tells us to create an algorithm for this, but we have not been given but a few ways to do this so I tried:

• $$n^2-2\cdot0$$ which would be $$36-0=36$$.
• $$n^2-2\cdot1$$ which would be $$36-2=34$$.
• $$n^2-2\cdot2$$ which would be $$36-4=32$$.
• $$n^2-2\cdot3$$ which would be $$36-6=30$$.
• $$n^2-2\cdot4$$ which would be $$36-8=28$$.
• $$n^2-2\cdot5$$ which would be $$36-10=26$$.

So my outputs come out as 36, 34, 32, 30, 28, 26.

Is this correct? If not, where am I going wrong?

• What's the context in which you encountered this task? Can you provide a link and/or full reference to the original source? – D.W. Sep 18 '20 at 5:08
• We are a question-and-answer site, so we require you to articulate a specific question about your situation. Please edit your question to make your question clear. When you say "Is this correct", please make it clear what the "this" is referring to. – D.W. Sep 18 '20 at 5:08
• We discourage "please check whether my answer is correct" questions, as only "yes/no" answers are possible, which won't help you or future visitors. See here and here. Can you edit your post to ask about a specific conceptual issue you're uncertain about? As a rule of thumb, a good conceptual question should be useful even to someone who isn't looking at the problem you happen to be working on. If you just need someone to check your work, you might seek out a friend, classmate, or teacher. – D.W. Sep 18 '20 at 5:09
• Your question is unreadable. You have to spend some time formatting it. – Yuval Filmus Sep 18 '20 at 10:14

I don't see an algorithm in your answer. Also, I doubt that if you convert your sequence of steps into an algorithm, then it will produce the correct answer for $$n=0,\ldots,5$$.
From the given examples, you can see that the first number in the sequence is always $$3n$$, and from then on the numbers increase by $$2$$ each time (as you mention; but then in your "algorithm" they decrease by $$2$$ each time), and in total there are $$2(n+1)$$ of them (you can see this since the length of the sequence increases by $$2$$ each time).
How do we convert this into an algorithm? An algorithm is a recipe that prints the sequence for every value of $$n$$, not for the particular value $$n=6$$. Also, it should reproduce the given sequences for $$n = 0,\ldots,5$$.
Your question makes me doubt that the lecturer has explained the concept of "algorithm", so instead, try to write a function in your favorite programming languages that given $$n$$, prints the sequence corresponding to $$n$$. Code is just a formal way of presenting an algorithm.