56
\$\begingroup\$

In this challenge, the goal is to recreate the On-Line Encyclopedia of Integer Sequences one sequence at a time. Similar to the Evolution of Hello World, each answer depends on a previous answer.

Over time, this challenge will create a "family tree" of the OEIS sequences. It is simple to add on to this tree.

  1. Find a previous answer, which can be at any depth N of the tree.
  2. Determine the first N numbers generated by that answer's sequence.
  3. Find a sequence in OEIS which starts with those same numbers and which hasn't been used before.
  4. Write a program to generate this new sequence you just found.
  5. Submit your answer as depth N+1

Since the level of your answer influences scoring, you should always add your answer onto the tree at the deepest level possible. If you cannot fit your answer anywhere on the tree, you can start a new branch of the tree and put your answer as depth 1.

Answer Requirements

There are a few ways to output a sequence.

The first option is to write a program or function that inputs a number (from STDIN or as an argument) and returns the Nth number in your chosen sequence. You can assume that the sequence will be defined for N and that N and S_N are "reasonably sized" (so it won't cause overflows). You can also use any reasonable indexing, such as 0 indexing, 1 indexing, or the indexing listed under "offset" on the sequence's OEIS page, that doesn't matter. The term produced by the first index must match the first term of the OEIS entry.

The second option is to write a program or function that inputs a number and returns the first N terms of the sequence. The first terms of the output must be the first terms of the OEIS entry (you can't leave off the first few terms). Consecutive terms must be delimited by arbitrary strings of non-digit characters, so 0,1 1.2/3,5;8,11 works but 011235811 does not count.

The third option is to create a program that outputs a continuous stream of numbers. Similarly to the second option, there must be delimiters between consecutive terms.

Your answer should contain a header like this to aid Stack Snippet parsing:

 # [language], [number] bytes, depth [number], A[new sequence] from A[old sequence] 

Your answer should contain the code to generate the sequence, along with the first few terms that any descendants will need to contain. These few terms should be preceded by the exact word terms: so that the controller can use them as part of the tree diagram. It is also recommended to write a description of the sequence you chose.

If your post is a depth 1 answer and thus has no ancestor, you should simply omit the from A[number] in your header.

Here is an example answer:

# Perl, 26 bytes, depth 3, A026305 from A084912

    various code here
    and here

The next answer should match the following terms:

    1, 4, 20

This sequence is .... and does ....

Chaining Requirements

In order to make this challenge more fair, there are restrictions on which answers you can chain yours to. These rules are mostly to prevent a single person from creating a whole branch of the tree by themselves or owning a lot of "root" nodes.

  • You cannot chain to yourself.
  • You cannot directly chain two of your answers to the same ancestor.
  • You cannot make more than one "Level 1" answer.

Also, if the ancestor was of depth N, your post must have depth N+1, even if more than the required number of terms agree.

Scoring

Your score as a user is the sum of the scores of all of your answers. The score of a single answer is determined by the following formula:

Answer Score = Sqrt(Depth) * 1024 / (Length + 256)

This scoring system should encourage users to submit a large number of deeper answers. Shorter answers are preferred over longer answers, but depth has a much larger influence.

Below is a stack snippet that generates a leaderboard as well as a tree diagram of all of the answers. I would like to thank Martin Büttner and d3noob as the sources for a lot of this code. You should click "Full screen" to see the complete results.

function answersUrl(t){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+t+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(t){answers.push.apply(answers,t.items),t.has_more?getAnswers():process()}})}function shouldHaveHeading(t){var e=!1,r=t.body_markdown.split("\n");try{e|=/^#/.test(t.body_markdown),e|=["-","="].indexOf(r[1][0])>-1,e&=LANGUAGE_REG.test(t.body_markdown)}catch(a){}return e}function shouldHaveScore(t){var e=!1;try{e|=SIZE_REG.test(t.body_markdown.split("\n")[0])}catch(r){}return e}function getAuthorName(t){return t.owner.display_name}function decodeEntities(t){return $("<textarea>").html(t).text()}function process(){answers=answers.filter(shouldHaveScore).filter(shouldHaveHeading),answers.reverse();var t={},e=[],r=1,a=null,n=1,s=[];answers.forEach(function(t){var r=t.body_markdown.split("\n")[0],a=getAuthorName(t),n=r.match(SEQUENCE_REG)[0];n=n.trim();var o="from A000000";PARENT_REG.test(r)&&(o=r.match(PARENT_REG)[0]),o=o.substring(5).trim(),"A000000"==o&&(o="OEIS");var i="";SEQDATA_REG.test(t.body_markdown)&&(i=t.body_markdown.match(SEQDATA_REG)[1]);for(var u=!0,c=0;c<e.length;++c)u=u&&!(e[c]===n);for(var l=!0,c=0;c<e.length;++c)l=!(!l||e[c]===n||e[c]===n+a||e[c]===o+a);e.push(n),e.push(n+a),e.push(o+a),u&&data.push({name:n,parent:o,term:i+" : ",author:decodeEntities(a),URL:t.share_link}),l&&s.push(t)}),answers.sort(function(t,e){var r=t.body_markdown.split("\n")[0].match(SEQUENCE_REG),a=e.body_markdown.split("\n")[0].match(SEQUENCE_REG);return a>r?-1:r>a?1:void 0}),answers.forEach(function(e){var o=e.body_markdown.split("\n")[0],i=(o.match(NUMBER_REG)[0],(o.match(SIZE_REG)||[0])[0]),u=parseInt((o.match(DEPTH_REG)||[0])[0]).toString(),c=o.match(SEQUENCE_REG)[0],l="from A000000";PARENT_REG.test(o)&&(l=o.match(PARENT_REG)[0]),l=l.substring(5);var d=o.match(LANGUAGE_REG)[1];d.indexOf("]")>0&&(d=d.substring(1,d.indexOf("]")));for(var p=getAuthorName(e),E=!1,h=0;h<s.length;++h)E=E||s[h]===e;if(E){var f=jQuery("#answer-template").html();i!=a&&(n=r),a=i,++r;var m=1024*Math.pow(parseInt(u),.5)/(parseInt(i)+256);f=f.replace("{{SEQUENCE}}",c).replace("{{SEQUENCE}}",c).replace("{{NAME}}",p).replace("{{LANGUAGE}}",d).replace("{{SIZE}}",i).replace("{{DEPTH}}",u).replace("{{LINK}}",e.share_link),f=jQuery(f),jQuery("#answers").append(f),t[p]=t[p]||{lang:d,user:p,size:"0",numanswers:"0",link:e.share_link},t[p].size=(parseFloat(t[p].size)+m).toString(),t[p].numanswers=(parseInt(t[p].numanswers)+1).toString()}});var o=[];for(var i in t)t.hasOwnProperty(i)&&o.push(t[i]);o.sort(function(t,e){return parseFloat(t.size)>parseFloat(e.size)?-1:parseFloat(t.size)<parseFloat(e.size)?1:0});for(var u=0;u<o.length;++u){var c=jQuery("#language-template").html(),i=o[u];c=c.replace("{{RANK}}",u+1+".").replace("{{NAME}}",i.user).replace("{{NUMANSWERS}}",i.numanswers).replace("{{SIZE}}",i.size),c=jQuery(c),jQuery("#languages").append(c)}createTree()}function createTree(){function t(){var t=i.nodes(root).reverse(),e=i.links(t);t.forEach(function(t){t.y=180*t.depth});var r=c.selectAll("g.node").data(t,function(t){return t.id||(t.id=++o)}),a=r.enter().append("g").attr("class","node").attr("transform",function(t){return"translate("+t.y+","+t.x+")"});a.append("a").attr("xlink:href",function(t){return t.URL}).append("circle").attr("r",10).style("fill","#fff"),a.append("text").attr("x",function(){return 0}).attr("y",function(){return 20}).attr("dy",".35em").attr("text-anchor",function(){return"middle"}).text(function(t){return t.term+t.name}).style("fill-opacity",1),a.append("text").attr("x",function(){return 0}).attr("y",function(){return 35}).attr("dy",".35em").attr("text-anchor",function(){return"middle"}).text(function(t){return t.author}).style("fill-opacity",1);var n=c.selectAll("path.link").data(e,function(t){return t.target.id});n.enter().insert("path","g").attr("class","link").attr("d",u)}var e=data.reduce(function(t,e){return t[e.name]=e,t},{}),r=[];data.forEach(function(t){var a=e[t.parent];a?(a.children||(a.children=[])).push(t):r.push(t)});var a={top:20,right:120,bottom:20,left:120},n=3203-a.right-a.left,s=4003-a.top-a.bottom,o=0,i=d3.layout.tree().size([s,n]),u=d3.svg.diagonal().projection(function(t){return[t.y,t.x]}),c=d3.select("body").append("svg").attr("width",n+a.right+a.left).attr("height",s+a.top+a.bottom).append("g").attr("transform","translate("+a.left+","+a.top+")");root=r[0],t(root)}var QUESTION_ID=49223,ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",data=[{name:"OEIS",parent:"null",term:"",author:"",URL:"https://oeis.org/"}],answers=[],page=1;getAnswers();var SIZE_REG=/\d+(?=[^\d&]*(?:&lt;(?:s&gt;[^&]*&lt;\/s&gt;|[^&]+&gt;)[^\d&]*)*,)/,DEPTH_REG=/\d+, A/,NUMBER_REG=/\d+/,LANGUAGE_REG=/^#*\s*([^,]+)/,SEQUENCE_REG=/A\d+/,PARENT_REG=/from\s*A\d+/,SEQDATA_REG=/terms:\s*(?:(?:-)?\d+,\s*)*((?:-)?\d+)/;
body{text-align: left !important}#answer-list{padding: 10px; width: 550px; float: left;}#language-list{padding: 10px; width: 290px; float: left;}table thead{font-weight: bold;}table td{padding: 5px;}.node circle{fill: #fff; stroke: steelblue; stroke-width: 3px;}.node text{font: 12px sans-serif;}.link{fill: none; stroke: #ccc; stroke-width: 2px;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><script src="http://d3js.org/d3.v3.min.js"></script><link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"><div id="answer-list"> <h2>Sequence List</h2> <table class="answer-list"> <thead> <tr> <td>Sequence</td><td>Author</td><td>Language</td><td>Size</td><td>Depth</td></tr></thead> <tbody id="answers"></tbody> </table></div><div id="language-list"> <h2>Leaderboard</h2> <table class="language-list"> <thead> <tr> <td>Rank</td><td>User</td><td>Answers</td><td>Score</td></tr></thead> <tbody id="languages"></tbody> </table></div><table style="display: none"> <tbody id="answer-template"> <tr> <td><a href="https://oeis.org/{{SEQUENCE}}">{{SEQUENCE}}</a></td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td>{{DEPTH}}</td><td><a href="{{LINK}}">Link</a> </td></tr></tbody></table><table style="display: none"> <tbody id="language-template"> <tr> <td>{{RANK}}</td><td>{{NAME}}</td><td>{{NUMANSWERS}}</td><td>{{SIZE}}</td></tr></tbody></table>

\$\endgroup\$
  • 5
    \$\begingroup\$ You know, I think this is might just be the single coolest codegolf.sx question I've ever seen asked. It's not just cool, but actually useful as an archive. \$\endgroup\$ – Todd Lehman Apr 26 '15 at 19:08
  • 3
    \$\begingroup\$ Given the OEIS is online, takes N terms of a sequence as a search term, and contains mathematica or maple code for many of the sequences, it would be possible to write a meta-entry which searched for the best scoring entry for which code exists in OEIS which is a descendent of any given entry here and posted it. \$\endgroup\$ – abligh Apr 26 '15 at 19:10
  • 2
    \$\begingroup\$ Can I recommend some way of marking on the graph the snippet generates that a node is terminal, ie there are no unused sequences of a greater depth available on the OEIS? \$\endgroup\$ – Claudiu Apr 27 '15 at 5:52
  • 1
    \$\begingroup\$ I think the only way to keep this challenge going would be to provide something where you give your username, and it lists the OEIS problems you could do, in order from highest depth to lowest. Otherwise it takes too long to find the next sequence to post. \$\endgroup\$ – Claudiu May 4 '15 at 22:38
  • 1
    \$\begingroup\$ The SVG is slightly too narrow. \$\endgroup\$ – CalculatorFeline Apr 8 '16 at 1:17

146 Answers 146

21
\$\begingroup\$

Parenthetic, 150 bytes, depth 4, A000292 from A000290

((()()())(()()()())((()())((()(()())))((()(())())((()()(()))(()(()()))((()(()))(()(()()))((())()))((()(()))(()(()()))((())()())))((())()()()()()()))))

The next answer should match the following terms:

0, 1, 4, 10

This is the sequence of tetrahedral numbers, the 3D generalisation of triangular numbers. The formula for this is

T(n) = n*(n+1)*(n+2)/6

Parenthetic is a Lisp-like language which uses parentheses to define everything. The above is a function ()()() which takes in n and outputs T(n). Call like:

((()()()())((())()()()()()()()))

Annotated

(
  define
  (() ()())

  f [][][]
  (() ()()())

  (
    lambda
    (() ())

    (
      n [[][]]
      (() (()()))
    )

    (
      div
      (() (())())

      (
        *
        (() ()(()))

        n
        (() (()()))

        (
          +
          (() (()))

          n
          (() (()()))

          1
          ((()) ())
        )

        (
          +
          (() (()))

          n
          (() (()()))

          2
          ((()) ()())
        )
      )

      6
      ((()) ()()()()()())
    )
  )
)


Test call:

(
  f
  (() ()()())

  6
  ((()) ()()()()()())
)
\$\endgroup\$
  • 19
    \$\begingroup\$ What in the world is this language? It's like a meaner version of Lisp. \$\endgroup\$ – Alex A. Apr 26 '15 at 19:39
  • 10
    \$\begingroup\$ @AlexA. That's not a Lisp! It's a full-blown Speech Impediment! \$\endgroup\$ – CJ Dennis May 30 '15 at 5:34
18
\$\begingroup\$

Pancake Stack, 118 bytes, depth 1, A000012

Put this kindercarnavalsoptochtvoorbereidingswerkzaamheden pancake on top!
Show me a pancake!
Eat all of the pancakes!

The next answer should match the following terms:

1

This prints the smallest divisor of n. Tested with the Python interpreter on the esolang wiki page. The interpreter expects a ~ on the line after to denote end of program, after which comes STDIN input (which will be ignored anyway).

Relevant instructions:

Put this <blah> pancake on top!                # Push length of <blah> 
Show me a pancake!                             # Output top of stack as char
Eat all of the pancakes!                       # Terminate the program

Previous answer

Put this  pancake on top!
[]
Put this kindercarnavalsoptochtvoorbereidingswerkzaamheden pancake on top!
Show me a pancake!
Put this delectable pancake on top!
Show me a pancake!
If the pancake is tasty, go over to "".

This one prints in an infinite loop. Additional instructions:

[<blah>]                                       # Define the label <blah>
If the pancake is tasty, go over to "<blah>".  # If top of stack nonzero, go to label

There are other instructions, but even so Pancake Stack is very cumbersome to use normally, thanks to a lack of numeric output and access to only the top two elements of the stack.

Unfortunately, the first line of this program seems necessary to prevent a bug concerning labels in the Python interpreter.

\$\endgroup\$
17
\$\begingroup\$

Python, 31 bytes, depth 4, A010060 from A000045

lambda n:sum(map(ord,bin(n)))%2

The next answer should match the following terms:

0, 1, 1, 0

This one's a favourite of mine, and it's the Thue-Morse sequence. There are at least two definitions of it:

  • The parity of ones in the binary expansion of n (used above), and
  • The sequence obtained by starting with 0, then repeatedly appending the bitwise complement of the sequence so far (i.e. 0 -> 01 -> 0110 -> 01101001 -> ...)

One of many cool things about this sequence is if we grab a turtle and do:

import turtle

turtle.speed(0)
n = 12

# Calculate first 2^n of Thue-Morse
tm = map(lambda n:sum(map(ord,bin(n)))%2, range(2**n)) 

# Move to top left
turtle.penup()
turtle.setx(-300)
turtle.sety(300)
turtle.pendown()

# For each num, go forward a unit if 0, or turn left 120 degrees if 1
for m in tm:
    if m == 0:
        turtle.forward(1)

    elif m == 1:
        turtle.left(120)

turtle.hideturtle()
turtle.mainloop()

we get this:

enter image description here

Look familiar?

\$\endgroup\$
15
\$\begingroup\$

MarioLANG, 265 bytes, depth 3, A016957 from A006370

                           <
         =================="
               (((+)< ))+(<
              ======" ===="
               >-))+!  >-(!
               "====#  "==#
          >-(>[!))   >[!(  !
          "====#=======#===#
;)++++++>[!))++++:
==========#=======

The next answer should match the following terms:

4, 10, 16

The sequence is merely the arithmetic progression 6n + 4.

MarioLANG is an esoteric programming language based on, well, Super Mario. Calculations are done in a Brainfuck-like way — there is a tape of cells which you can increment/decrement.

The relevant BF-like commands here are:

+      Increment current memory cell
-      Decrement current memory cell
(      Move memory pointer left
)      Move memory pointer right
;      Numeric input
:      Numeric output
[      Skip next instruction is current cell is zero

So where's the Mario? Well Mario is your instruction pointer, and he starts on the left (where ; is). Mario keeps executing instructions as long as he's on the ground =, and when he falls the program terminates.

The relevant instructions for this are:

=      Ground for Mario to stand on
<      Make Mario move leftward
>      Make Mario move rightward
!      Make Mario stop moving
#      Elevator start
"      Elevator end

All in all, the program does this:

Put input (n) in cell 0
Increment cell 1 to 6
While cell 1 is not zero...
    Decrement cell 1
    Move n from cell 0 to cells 2, 3
    Move n from cell 2 to cell 0
Increment cell 3 by 4
Output as num

Tested with the Ruby interpreter. Note that the language has a lot of undefined behaviour, such as what happens to instructions Mario meets as he falls, so I tried to avoid any of that.

\$\endgroup\$
12
\$\begingroup\$

Brainfuck, 2 bytes, depth 2, A000030 from A001477

,.

A000030 is the sequence of the initial digits of the non-negative integers, so this simply reads the first digit character and writes it back. The next sequence should start with the terms:

0, 1
\$\endgroup\$
  • 12
    \$\begingroup\$ This may be the shortest useful Brainfuck program I've ever seen. \$\endgroup\$ – Alex A. Apr 26 '15 at 19:41
9
\$\begingroup\$

Piet, 16 bytes, depth 3, A000035 from A000030

enter image description here

The next answer should match the following terms:

0, 1, 0

This is Piet, so the "bytes" are really codels. Here it is at a larger codel size:

enter image description here

The program simply reads in n and outputs n modulo 2.

\$\endgroup\$
9
\$\begingroup\$

Marbelous, 7 bytes, depth 3, A011760 from A000027

It's been a while since this site has seen a Marbelous answer!

}0
<D++

The next answer should start with the terms:

1, 2, 3

You can try the code in es1024's Stack Snippet interpreter. In put is given via command-line argument, and you should choose "Display output as decimal numbers". Otherwise, the result will be output as a byte value, which is technically also fine.

The sequence is the sequence of "elevator buttons in U.S.A.", i.e. all positive integers except 13. Note that Marbelous is limited to 8-bit numbers, but as far as I'm aware there are no buildings with anywhere near 256 floors. :)

Marbelous is a 2D language where data flows through the code in the form of marbles (byte values) falling down the grid. }0 gets replace with the first command-line argument. <D is a switch which acts as an empty cell to marbles less than 13 (the D is in base 36), so that inputs 1 to 12 pass through unaffected. If the marble is equal to or greater than 13, the marble is deflected to the right and passes through the ++ which increments the value by 1. In either case the marble then falls off the board, which prints its value.

\$\endgroup\$
8
\$\begingroup\$

Rail, 56 bytes, depth 4, A033547 from A002378

$'main'
 0/aima19-@
@------e<
  /()(!!)-@
@-()m5a()m3do#

The next answer should match the following terms:

0, 2, 6, 14

The program reads in n from STDIN and outputs n*(n^2+5)/3, which was a guess at the magic numbers for the nuclear shell model from the 1940s.

Rail is a 2D language which is themed around train tracks. The above code is golfed using @ reflectors which reverse the direction of the train, in order to reduce the number of newlines. Here it is ungolfed:

$ 'main'
 \
  0
   \ /--aima19--\
    |           |
    \--e-------<
                \
                 \-(!n!)-(n)-(n)-m-5-a-(n)-m-3-d-o-#

Note how Rail starts at the top left and begins moving vertically down-right.

The stack manipulation commands used are:

0-9       Push 0-9 respectively
e         Push t (true) if EOF, else f (false)
i         Input char
o         Output
a         Add
m         Multiply
(!n!)     Store top of stack as variable n
(n)       Push variable n to stack
#         Halt program

The train branches at junctions >v<^, turning right if the top of the stack is true, otherwise left if false.

\$\endgroup\$
8
\$\begingroup\$

Starry, 22 bytes, depth 4, A008619 from A000142

      + + +*,  +   **.

The next answer should match the following terms:

1, 1, 2, 2

The sequence consists of the positive integers repeated twice. The program reads in a number from STDIN and calculates 1 + floor(n/2).

Starry is an esoteric language implemented in Ruby which was part of a book on... making esoteric languages in Ruby. Each instruction is determined by the number of spaces before one of +*.,`'. All other characters are ignored, so the above is equivalent to

      +
 + +*,
  +   *
*.

which looks a lot more starry! (note the trailing spaces)

The relevant commands are:

Spaces     Final      Instruction
------     -----      -----------
n >= 5     +          Push n-5 to stack
1          +          Duplicate top of stack
0 mod 5    *          Add
0 mod 2    ,          Input num
2          +          Swap top 2
3 mod 5    *          Divide
0 mod 2    .          Output num

Previous answer, 53 bytes

      +` +.               + + .  + +.  + .      +* +'

This generates the sequence ad infinitum instead. Some additional commands are:

Spaces     Final      Instruction
------     -----      -----------
1 mod 2    .          Output as ASCII char
n          `          Mark a label n
n          '          Pop and if nonzero, jump back to label n
\$\endgroup\$
7
\$\begingroup\$

Mathematica, 20 bytes, depth 6, A037965 from A104631

Binomial[2#-2,#-1]#&

This is an unnamed function which simply computes the definition of the sequence. The next sequence should start with the terms:

0, 1, 4, 18, 80, 350
\$\endgroup\$
  • \$\begingroup\$ Leaf node (no other sequences) \$\endgroup\$ – CalculatorFeline Apr 8 '16 at 1:11
7
\$\begingroup\$

CJam, 34 bytes, depth 14, A157271 from A238263

qi_,_m*{~2@#3@#*}$<::+1f&_:+\1-,e>

The next answer should start with the terms:

1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7

but there aren't any left which haven't been done already.

Let D(n) be the set of the first n 3-smooth numbers: that is, integers whose prime factors are a subset of {2, 3}. Let S(n) be the largest subset of D(n) which doesn't itself contain any subset of the form {x, 2x} or {y, 3y}. Then A157271 is the size of S(n).

\$\endgroup\$
  • 1
    \$\begingroup\$ Ah nice, I was looking at this one but wasn't quite clear what their explanation meant. Yours is much clearer. \$\endgroup\$ – Claudiu Apr 28 '15 at 4:06
6
\$\begingroup\$

Golfscript, 3 bytes, depth 3, A000290 from A000030

~2?

The next answer should match the following terms:

0, 1, 4

This sequence is simply the square numbers, so the program takes a number and outputs its square.

\$\endgroup\$
6
\$\begingroup\$

Prelude, 16 bytes, depth 1, A000211

3(v!  v)
4 ^+2-^

I thought I'd start a tree with a less obvious initial number. This is a generalised Fibonacci sequence with definition a(0) = 4, a(1) = 3, a(n) = a(n-1) + a(n-2) - 2. Consequently, this is mostly a simple adaptation of my Prelude Fibonacci solution. The above is a program which prints an infinity stream of the numbers. It assumes the Python interpreter which outputs numbers instead of individual characters.

The next answer should start with the terms:

4
\$\endgroup\$
6
\$\begingroup\$

Clip, 0 bytes, depth 2, A000027 from A000012

Given a number n, prints the nth number in the sequence 1, 2, 3, 4...

The next answer should start with the terms:

1, 2
\$\endgroup\$
5
\$\begingroup\$

J, 4 bytes, depth 4, A001563 from A000290

(*!)

The next answer should match the following terms:

0, 1, 4, 18

This sequence is the number multiplied by its factorial. In J (fg)x is f(x,g(x)) here x*factorial(x).

\$\endgroup\$
  • \$\begingroup\$ You could leave out the parentheses for 2 bytes: *! \$\endgroup\$ – ɐɔıʇǝɥʇuʎs Apr 27 '15 at 7:28
  • \$\begingroup\$ @ɐɔıʇǝɥʇuʎs I will not going to argue with anyone who says I can't leave them out for ~1/128 part of the score. :) \$\endgroup\$ – randomra Apr 27 '15 at 7:37
5
\$\begingroup\$

Mathematica, 48 bytes, depth 5, A104631 from A001563

SeriesCoefficient[((x^5-1)/(x-1))^#,{x,0,2#+1}]&

The next answer should match the following terms:

0, 1, 4, 18, 80

Barring the long function names, Mathematica absolutely rocks at this challenge. This one is simply the coefficient of x^(2n+1) in the expansion of

(1 + x + x^2 + x^3 + x^4)^n
\$\endgroup\$
5
\$\begingroup\$

Element, 13 bytes, depth 3, A000045 from A000030

1_'0[3:~2@+]`

A000045 represents the Fibonacci numbers. Each term in the sequence is the sum of the previous two terms. It is notable because the ratio between consecutive terms approaches the golden ratio, also known as phi. Somewhat interestingly, the OEIS entry starts with 0, 1 instead of the common 1, 1. The next answer should match the terms:

0, 1, 1
\$\endgroup\$
5
\$\begingroup\$

Prelude, 1 byte, depth 2, A000004 from A001477

!

The next answer should match the following terms:

0, 0

This program takes in n as input, completely ignores it, and outputs the zero constant. It requires NUMERIC_OUTPUT = True in the Python interpreter.

The nice thing about Prelude is that it has an infinite supply of zeroes at the bottom of the stack, so all that was needed was a single output command.

\$\endgroup\$
4
\$\begingroup\$

Perl, 10 bytes, depth 1, A001477

To kick things off, here is a simple sequence.

print$_=<>

This represents the non-negative numbers 0, 1, 2, 3, etc. by printing the input number. The next sequence should start with the terms:

0
\$\endgroup\$
4
\$\begingroup\$

GolfScript, 9 bytes, depth 4, A051682 from A002275

~.9*7-*2/

The next answer should match the following terms:

0, 1, 11, 30

This simply uses the formula for hendecagonal numbers found on the OEIS page.

\$\endgroup\$
4
\$\begingroup\$

Deadfish, 4 bytes, depth 2, A005563 from A001477

isdo

This sequence is defined as (n+1)^2-1, which is exactly what this program does. Since Deadfish has no input, it assumes the accumulator is at the desired input number. The next answer should start with the terms:

0, 3
\$\endgroup\$
4
\$\begingroup\$

APL, 13 bytes, depth 4, A000108 from A000142

{(⍵!2×⍵)÷⍵+1}

Catalan numbers! Indexing starts at zero for these. The next answer should start with the terms:

1, 1, 2, 5
\$\endgroup\$
4
\$\begingroup\$

GolfScript, 31 bytes, depth 11, A029030 from A242681

~][11.(2]{:C;{{.C-.)0>}do;}%}/,

The next answer should match the following terms:

1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 7

but it won't be able to: this is a leaf of the tree. This sequence is the number of ways of giving change with coins of value 1, 2, 10, and 11.

\$\endgroup\$
  • 3
    \$\begingroup\$ A258000: 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 7, 42 - Some strange sequence they asked for at codegolf.stackexchange.com \$\endgroup\$ – schnaader Apr 27 '15 at 11:19
4
\$\begingroup\$

Retina, 1 byte, depth 3, A055642 from A001333

.

The next answer should start with the terms:

1, 1, 1

I think this is the first time I used Retina in something else than Replace mode. If only a single file is given without any options, Retina assumes Match mode, which by default counts the number of matches of the given regex in the input. This regex is . and matches any character. Therefore, this program returns the number of digits of the input which is A055642.

\$\endgroup\$
3
\$\begingroup\$

Clip, 24 bytes, depth 4, A049666 from A002275

/F*5nx5[Fx?<x3O]+F(xF((x

The next answer should match the following terms:

0, 1, 11, 122

The sequence is just Fibonacci(5n)/5. See the examples page for an explanation.

\$\endgroup\$
3
\$\begingroup\$

Clip, 37 bytes, depth 5, A227327 from A000292

[t/m++#t4*2#t3*8#t2?%t2+*2t9]*8t]48]n

Possible ways to choose two points on a triangular grid of side n, excluding rotations and reflections. The example given is: for n = 3, there are 4 ways:

  X        X        X        .
 X .      . .      . .      X X
. . .    X . .    . X .    . . .

The next sequence must start with the following terms:

0, 1, 4, 10, 22
\$\endgroup\$
3
\$\begingroup\$

APL, 24 bytes, depth 6, A025581 from A182712

{¯1-⍵-2!1+⌊.5+.5*⍨2×1+⍵}

The sequence A025581 is the sequence of... Im not quite sure to be honest. It scares me.

Indexing starts at 0 and the function just calculates the sequence by definition.

The next sequence should start with the terms:

0, 1, 0, 2, 1, 0
\$\endgroup\$
  • \$\begingroup\$ Decreasing integers m to 0 followed by decreasing integers m+1 to 0, etc. That might help. \$\endgroup\$ – CalculatorFeline Jun 5 '17 at 15:52
3
\$\begingroup\$

><>, 25 bytes, depth 2, A001333 from A002522

301-v >rn;
*2@:<r^!?:-1r+

These are the numerators of the continued fraction convergents to sqrt(2). The code needs the user to prepopulate the stack with the index of the convergent that should be returned. Indexing starts at 1. The next answer should start with the terms:

1, 1
\$\endgroup\$
3
\$\begingroup\$

J, 44 bytes, depth 10, A242681 from A026233

f=.(,(<:*+)"0/~~.50,25,(,+:,3*])1+i.20)+/@:=]

The next answer should start with the terms:

1, 1, 2, 2, 3, 3, 4, 4, 5, 5

Something closer to everyday life: "the number of ways that a score of n can be obtained using two darts on a standard dartboard". Only the unordered score-pair matters. Starting offset is two as in the OEIS page. Usage:

f 2 => 1
f 72 => 12
\$\endgroup\$
3
\$\begingroup\$

R, 20 bytes, depth 11, A194964 from A242681

1+floor(scan()/5^.5)

The next answer should match the following terms:

1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5

The sequence A194964 gives for each n the result of 1+[n/sqrt(5)] where [ means "floor". The R function takes input as stdin.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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