# Evolution of OEIS

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.

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.

 # [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.

# 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> • 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. – Todd Lehman Apr 26 '15 at 19:08 • 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. – abligh Apr 26 '15 at 19:10 • 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? – Claudiu Apr 27 '15 at 5:52 • 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. – Claudiu May 4 '15 at 22:38 • The SVG is slightly too narrow. – CalculatorFeline Apr 8 '16 at 1:17 ## 146 Answers # Pyth, 26 bytes, depth 7, A136860 from A136855 L{jbT@f<+yTy*TTy10467U^5QQ  ### Explanation L define function y(b): returns { set of jbT base-10 digits of b @ Q take Nth item f filter U^5Q integers T in 0..(5^N)-1 + union of yT digits of T y*TT digits of T^2 < is subset of y10467 digits of 10467  The Nth value will always be less than 5^N, since: 1. All powers of 10 are in the sequence, as numbers of form 10^k and (10^k)^2 = 10^2k will always contain only digits 1 and 0. 2. All powers of 10 multiplied by 4 are in the sequence, as numbers of form 4*10^k and (4*10^k)^2 = 16*10^2k will always contain only digits 4, 1, 6 and 0. 3. Therefore there are at least two values in the sequence for each power of 10. For each value, we do the next power of 5, which means the next power of 25 for each value. This will always contain at least two values per power, since 25^m >= 10^m whenever m >= 0. The next answer should match the following terms: 0, 1, 4, 10, 40, 100, 400  # PARI/GP, 22 bytes, depth 4, A004601 from A010052 n->floor(Pi*2^(n-1))%2  Binary expansion of π. The next sequence should start with the terms: 1, 1, 0, 0  # Julia, 27 bytes, depth 5, A010057 from A004601 f(n)=floor(n^(1/3))^3<n?0:1  Next sequence should start with the terms: 1, 1, 0, 0, 0  This sequence gives 1 if n is a cube and 0 if not. • I think A?1:0 is valid, and it saves one char over int(A). It also allows flipping the condition and testing < rather than == for another char. – Peter Taylor Apr 28 '15 at 9:03 • @PeterTaylor thanks! indeed it worked. – plannapus Apr 28 '15 at 9:08 # Python, 21 bytes, depth 7, A049472 from A028391 lambda n:int(n/2**.5)  Next sequence on that branch should start with the terms: 0, 0, 1, 2, 2, 3, 4  # R, 100 bytes, depth 5, A000110 from A000108 n=scan();a=0;for(k in 1:n){K=0:k;J=factorial(K);a=a+sum(rep(c(1,-1)*(-1)^k,l=k+1)*K^n/(J*rev(J)))};a  The next sequence should match the following terms: 1, 1, 2, 5, 15  This sequence is the Bell numbers, i. e. the number of ways to partition a set of n labeled elements. My code, with indents and newlines: n=scan() a=0 for(k in 1:n){ K=0:k J=factorial(K) a=a+sum(rep(c(1,-1)*(-1)^k,l=k+1)*K^n/(J*rev(J))) } a  What's inside the loop is an implementation of the "Stirling numbers of second kind", which happens to have been implemented also in R in package gmp, so the code could be golfed to 68 chars: n=scan();sum(sapply(1:n,function(k)as.integer(gmp::Stirling2(n,k))))  # R, 26 bytes, depth 4, A014684 from A000142 n=scan();n-(sum(n%%2:n)<2)  List of natural integers minus one if the integer is a prime. The next sequence should start with the terms: 1, 1, 2, 4  # CJam, 64 bytes, depth 9, A072490 from A057359 ri,(;{0:M;X\{\)0:A;{11$%0{_@@/\A):A}?}gAMe>:M;\_1>}g;;M1=}%0+:+  The next sequence should start with the terms: 0, 0, 1, 2, 2, 3, 4, 5, 5  Here's an easy-to-understand sequence: the number of squarefree numbers less than n. A squarefree number is one whose prime decomposition contains no repeated factors. I am betting this can be golfed more. I figure out whether a number k is squarefree by iterating j from 2 to k and dividing the number by j as many times as it fits, then storing this in A. Then I keep track of the max As in M, so M is the max number of repeated prime factors. If M==1, the number if squarefree. Then I apply this to all the numbers in the range and sum. But there must be a cleaner way. On the other hand I like that gAMe accidentally appears in the code. # Mathematica, 66 bytes, depth 3, A000002 from A000027 Nest[Mod[Flatten@MapIndexed[Table[#2,{#}]&,#],2,1]&,{1,2},#][[#]]&  The next answer should start with the terms: 1, 2, 2  A longer, but more interesting solution: k[n_] := StringTake[ NestWhile[ StringReplace[#, {"1 1" -> "2 1", "1 2" -> "2 1 1", "2 1" -> "2 2 1", "2 2" -> "2 2 1 1"}] &, "1,2 2", StringLength@# < 2 n &], 2 n]  Related question: Generate a Kolakoski sequence # CJam 0.6.5, 52 bytes, depth 9, A045841 from A103181 ]:Rri{i48-}%e!{_,),(;{\_@<_)2%{;aR+:R}{}?}/}/];RR&,  The next sequence should start with the following terms: 0, 1, 0, 1, 0, 1, 0, 1, 0  This is the "number of distinct odd numbers formed from the digits of n". e.g A(37) is 4 because you have 3, 7, 37, and 73, while A(33) is 2 because you have 3 and 33. e! gets permutations, but without choosing a subset. So for all permutations I take the first 1 through d digits in turn, see if they are odd, and if so add it to R. RR& at the end removes duplicates and then I output the length. I saved a bunch of bytes by leaving the stack littered with garbage and wiping it all out at the end with ];. # CJam, 28 bytes, depth 9, A098388 from A084054 ri:N1U{\)_mp@+_N=!}g;2mLm[p;  The next sequence should start with the following terms: 1, 1, 2, 2, 3, 3, 4, 4, 4  This is the floor of the binary logarithm of the nth prime. 1U{\)_mp@+_N=!}g; computes the Nth prime, and 2mLm[p prints the floor of the binary logarithm. This uses built-in primality testing mp, so if that is considered cheating let me know and I will use a non-built-in primality tester. I wonder if this could be golfed a bit more. # CJam, 17 bytes, depth 8, A194175 from A049472 ri,{)7mq*1%}%:+m[  The next sequence should start with the following terms: 0, 0, 1, 2, 2, 3, 4, 4  This one seemed like a nice and short one. It's simply: $A(n)=\left\lfloor\sum\limits_{k=1}^nfrac(k\sqrt{7})\right\rfloor$ where frac is the fractional part. Very well-suited to CJam. # Python 3, 66 bytes, depth 2, A000043 from A000040 n=2 while n:k=2**n-1;any(k%d<1for d in range(2,k))or print(n);n+=1  The next answer should match the following terms: 2, 3  These are the positive integers n such that 2^n - 1 is prime, i.e. n is the exponent of a Mersenne prime. It's easy to see that n itself must be prime, since if d divides n then 2^d - 1 is a divisor of 2^n - 1. Equivalently, by the Euclid-Euler theorem, these are also the integers n such that 2^(n-1) (2^n - 1) is an even perfect number (sum of divisors equals itself). This Python program uses trial division, so it only manages to get up to 19 before it starts taking a while. For comparison, simply replacing the primality check with the probabilistic Miller-Rabin manages up to 607 in a reasonable amount of time. ## Seriously, 14 bytes, depth 3, A000125 from A000027 ,;3@^@5*+6+6@\  Try it online! The next answer should match the following terms: 1, 2, 4  • @ՊՓԼՃՐՊՃՈԲՍԼ It's not required to chain off of the most recent answer. – Mego Feb 1 '16 at 4:59 # 𝔼𝕊𝕄𝕚𝕟, noncompeting, depth 4, A001614 from A000125 17 chars / 25 bytes: 2*ï-⌊ ½+½*√ 8*ï-7  Try it here (Firefox only). The next answer should match: 1, 2, 4, 5  • Language made after this challenge. – Mama Fun Roll Mar 9 '16 at 21:34 • I think that non-competing answers shouldn't be posted for this. At the very least, it's messing up the snippet/tree. Also, you'd need to move "noncompeting" somewhere else. Your answer has to follow the format. – mbomb007 Mar 9 '16 at 22:29 # Mathematica, 14 bytes, depth 5, A129323 from A001563 BellB[#-1,2]#&  Derived from the Mathematica program given with the sequence. Ignore any messages. The next answer should start with the terms: 0, 1, 4, 18, 88  # Mathematica, 11 bytes, depth 4, A004188 from A002275 (3#^3-#)/2&  The next answer should start with the terms: 0, 1, 11, 39  # Mathematica, 58 bytes, depth 12, A029031 from A025766 SeriesCoefficient[1/Times@@(1-x^#&)/@{1,2,11,12},{x,0,#}]&  Just uses the definition of the series. The next answer should start with the terms: 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 7  # Mathematica, 40 bytes, depth 10, A096125 from A026233 NestWhile[#+1&,a=#;1,!((a-#)!^2∣a!)&]&  Just increments k until the condition is met. See the sequence definition for more information. The next answer should start with the terms: 1, 1, 2, 2, 3, 3, 4, 4, 5, 4  # Mathematica, 34 bytes, depth 10, A173923 from A045841 Floor[#~IntegerReverse~2/8]~Mod~2&  Uses a definition given with the sequence. Requires Mathematica 10.3 or higher to run. Starts at index 8. The next answer should start with the terms: 0, 1, 0, 1, 0, 1, 0, 1, 0, 0  # Mathematica, 68 bytes, depth 11, A096088 from A096972 For[a=1,1>0,Print/@Union@Flatten[PowerModList[#,4,a]&/@0~Range~a++]]  Outputs terms, followed by newlines. The sequence definition is pretty complicated, so I won't go into it here. The next answer should start with the terms: 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 3  # Mathematica, 98 bytes, depth 10, A175835 from A083912 Count[Normal@SeriesData[x,0,Reverse@RealDigits[EulerGamma,10,#][[1]],0,#,1]~NRoots~x,_Real,{1,2}]&  Pretty random sequence definition. Makes more sense if you read the sequence page. The next answer should start with the terms: 0, 1, 0, 1, 0, 1, 0, 1, 0, 1  # Mathematica, 20 bytes, depth 10, A225545 from A098388 Floor@*Exp@*LambertW  Does what it says on the tin (takes ⌊eW(n)⌋). LambertW appears to be an alias for ProductLog. The next answer should start with the terms: 1, 1, 2, 2, 3, 3, 4, 4, 4, 5  # Mathematica, 48 bytes, depth 9, A025640 from A022336 SortBy[0~Range~#~Tuples~2,3^# 4^#2&@@#&][[#,1]]&  Exponent of 3 (value of i) in nth number of form 3i∙4j. The next answer should start with the terms: 0, 1, 0, 2, 1, 0, 3, 2, 1  # Mathematica, 30 bytes, depth 9, A038668 from A057359 Floor[#/LucasL@a]~Sum~{a,#}-#&  An = ⌊n/L(2)⌋ + ⌊n/L(3)⌋ + ⌊n/L(4)⌋ + ⌊n/L(5)⌋ + ⋯, where L(n) denotes the nth term in the Lucas sequence. The next answer should start with the terms: 0, 0, 1, 2, 2, 3, 4, 5, 6  # Haskell, 32 bytes, depth 7, A018819 from A016116 l=1:zipWith(+)l(tail$l>>=(:[0]))


This defines an infinite list containing all the values.

As more easily readable function that (could be golfed some more and) is much less efficient the sequence can be defined by

a 0=1; a m|odd m=a(m-1); a m=a(m-1)+a(mdiv2)


So it starts with 1, and then we always take the previous value and, in the even case, add the value from m/2. The list definition uses l>>=(:[0]) to create a list that alternates between values from l and zeroes ([l0,0,l1,0,l2,0,...]) to achieve the same effect.

The sequence is the binary partition function, giving the number of partitions of a number into powers of 2, for example for 5 it is 4, because 5 can be written in four ways: as 1+1+1+1+1, 1+1+1+2, 1+2+2 and 1+4.

The next sequence should match the following terms:

1, 1, 2, 2, 4, 4, 6


## Python 2, 59 bytes, depth 4, A000123 from A000125

i=0;j=1;s=1,
while 1:print s[-1];s+=(s[-1]+s[i],);i+=j;j^=1


Try it online. Uses a modified version so you can actually read the output, since infinite output is hard to read.

The next answer should match the following terms:

1, 2, 4, 6
`
• Haha. My score is 0... – mbomb007 Mar 9 '16 at 22:36
• This is because it has a link in the answer title. This would be one aspect of the parser to improve if a similar challenge is ever posted in the future. – PhiNotPi Mar 19 '17 at 15:22