# One OEIS after another

As of 13/03/2018 16:45 UTC, the winner is answer #345, by Khuldraeseth na'Barya. This means the contest is officially over, but feel free to continue posting answers, just so long as they follow the rules.

As well, just a quick shout out to the top three answerers in terms of numbers of answers:

3. Hyper Neutrino - 26 answers

This is an answer chaining question that uses sequences from OEIS, and the length of the previous submission.

This answer chaining question will work in the following way:

• I will post the first answer. All other solutions must stem from that.
• The next user (let's call them userA) will find the OEIS sequence in which its index number (see below) is the same as the length of my code.
• Using the sequence, they must then code, in an unused language, a program that takes an integer as input, n, and outputs the nth number in that sequence.
• Next, they post their solution after mine, and a new user (userB) must repeat the same thing.

The nth term of a sequence is the term n times after the first, working with the first value being the first value given on its OEIS page. In this question, we will use 0-indexing for these sequences. For example, with A000242 and n = 3, the correct result would be 25.

## However!

This is not a , so shortest code doesn't matter. But the length of your code does still have an impact. To prevent the duplication of sequences, your bytecount must be unique. This means that no other program submitted here can be the same length in bytes as yours.

If there isn't a sequence for then length of the last post, then the sequence for your post is the lowest unused sequence. This means that the sequences used also have to be unique, and that the sequence cannot be the same as your bytecount.

After an answer has been posted and no new answers have been posted for more than a week, the answer before the last posted (the one who didn't break the chain) will win.

## Input and Output

Generic input and output rules apply. Input must be an integer or a string representation of an integer and output must be the correct value in the sequence.

## Formatting

# N. language, length, [sequence](link)

code

*anything else*


## Rules

• You must wait for at least 1 hour before posting an answer, after having posted.
• You may not post twice (or more) in a row.
• The index number of a sequence is the number after the A part, and with leading zeros removed (e.g. for A000040 the index number is 40)
• You can assume that neither the input nor the required output will be outside your languages numerical range, but please don't abuse this by choosing a language that can only use the number 1, for example.
• If the length of your submission is greater than 65536 characters long, please provide a link to a way to access the code (pastebin for example).
• n will never be larger than 1000, or be out of bounds for the sequence, simply to prevent accuracy discrepancies from stopping a language from competing.
• Every 150 (valid) answers, the number of times a language may be used increases. So after 150 solutions have been posted, every language may be used twice (with all previous answers counting towards this). For instance, when 150 answers have been posted, Python 3 may be used twice, but due to the fact that it has already been used once, this means it can only be used once more until 300 answers have been posted.
• Please be helpful and post a link to the next sequence to be used. This isn't required, but is a recommendation.
• Different versions of languages, e.g. Python 2 and Python 3 are different languages. As a general rule, if the different versions are both available on Try It Online, they are different languages, but keep in mind that this is a general rule and not a rigid answer.
• It is not banned, but please try not to copy the code from the OEIS page, and actually try to solve it.
• Hardcoding is only allowed if the sequence is finite. Please note that the answer that prompted this (#40) is the exception to the rule. A few answers early in the chain hardcode, but these can be ignored, as there is no good in deleting the chain up to, say, #100.

var QUESTION_ID=133754,OVERRIDE_USER=66833;function shareUrl(i){return"https://codegolf.stackexchange.com/a/"+i}function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getTemplate(s){return jQuery(jQuery("#answer-template").html().replace("{{PLACE}}",s.index+".").replace("{{NAME}}",s.user).replace("{{LANGUAGE}}",s.language).replace("{{SEQUENCE}}",s.sequence).replace("{{SIZE}}",s.size).replace("{{LINK}}",s.link))}function search(l,q){m=jQuery("<tbody id='answers'></tbody>");e.forEach(function(s){if(!q||(l==0&&RegExp('^'+q,'i').exec(s.lang_name))||(l==1&&q===''+s.size)){m.append(jQuery(getTemplate(s)))}});jQuery("#answers").remove();jQuery(".answer-list").append(m)}function sortby(ix){t=document.querySelector('#answers');_els=t.querySelectorAll('tr');els=[];for(var i=0;i<_els.length;i++){els.push(_els[i]);}els.sortBy(function(a){a=a.cells[ix].innerText;return ix==0||ix==4?Number(a):a.toLowerCase()});for(var i=0;i<els.length;i++)t.appendChild(els[i]);}function checkSize(x){if(!x)return jQuery("#size-used").text("");var i=b.indexOf(+x);if(i<0)return jQuery("#size-used").text("Available!");var low=+x,high=+x;while(~b.indexOf(low))low--;while(~b.indexOf(high))high++;jQuery("#size-used").text(("Not available. The nearest are "+low+" and "+high).replace("are 0 and","is"))}function checkLang(x){}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.answer_id;answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return (e.owner.user_id==OVERRIDE_USER?"<span id='question-author'>"+e.owner.display_name+"</span>":e.owner.display_name)}function process(){b=[];c=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);if(a){e.push({user:getAuthorName(s),size:+a[4],language:a[2],lang_name:a[3],index:+a[1],sequence:a[5],link:shareUrl(s.answer_id)});if(b.indexOf(+a[4])>=0&&c.indexOf(+a[4])<0){c.push(+a[4])};b.push(+a[4])}else{jQuery('#weird-answers').append('<a href="'+shareUrl(s.answer_id)+'">This answer</a> is not formatted correctly. <b>Do not trust the information provided by this snippet until this message disappears.</b><br />')}}),e.sortBy(function(e){return e.index});e.forEach(function(e){jQuery("#answers").append(getTemplate(e))});var q="A"+("000000"+e.slice(-1)[0].size).slice(-6);jQuery("#next").html("<a href='http://oeis.org/"+q+"'>"+q+"</a>");c.forEach(function(n){jQuery('#weird-answers').append('The bytecount '+n+' was used more than once!<br />')})}Array.prototype.sortBy=function(f){return this.sort(function(a,b){if(f)a=f(a),b=f(b);return(a>b)-(a<b)})};var ANSWER_FILTER="!*RB.h_b*K(IAWbmRBLe",COMMENT_FILTER="!owfmI7e3fd9oB",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page,e=[];getAnswers();var SCORE_REG=/<h\d>\s*(\d+)\.\s*((?:<a [^>]+>\s*)?((?:[^\n,](?!<\/a>))*[^\s,])(?:<\/a>)?),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*, ((?:<a[^>]+>\s*)?A\d+(?:\s*<\/a>)?)\s*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important;font-family:Roboto,sans-serif}#answer-list,#language-list{padding:10px;/*width:290px*/;float:left;display:flex;flex-wrap:wrap;list-style:none;}table thead{font-weight:700}table td{padding:5px}ul{margin:0px}#board{display:flex;flex-direction:column;}#language-list li{padding:2px 5px;}#langs-tit{margin-bottom:5px}#byte-counts{display:block;margin-left:15px;}#question-author{color:purple;text-shadow: 0 0 15px rgba(128,0,128,0.1);}#label-info{font-weight: normal;font-size: 14px;font-style: italic;color: dimgray;padding-left: 10px;vertical-align: middle; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"><p id="weird-answers"></p><p>Currently waiting on <span id="next"></span></p><span>Search by Byte Count: <input id="search" type="number" min=1 oninput="checkSize(this.value);search(1,this.value)" onclick="document.getElementById('search2').value='';!this.value&&search(0,'')"/> <span id="size-used"></span></span><br><span>Search by Language: <input id="search2" oninput="checkLang(this.value);search(0,this.value)" onclick="document.getElementById('search').value='';!this.value&&search(0,'')"/> <span id="language-used"></span></span><h2>Answer chain <span id="label-info">click a label to sort by column</span></h2><table class="answer-list"><thead><tr><td  onclick="sortby(0)">#</td><td onclick="sortby(1)">Author</td><td onclick="sortby(2)">Language</td><td onclick="sortby(3)">Sequence</td><td onclick="sortby(4)">Size</td></tr></thead><tbody id="answers"></tbody></table><table style="display: none"><tbody id="answer-template"><tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SEQUENCE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody></table><table style="display: none"><tbody id="language-template"><tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SEQUENCE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody></table>

• Comments are not for extended discussion; this conversation has been moved to chat. – Dennis Oct 31 '17 at 2:49
• Is it OK if a program would need a better floating-point accuracy for the builtin float/double type in order to produce values for larger n? – NieDzejkob Nov 21 '17 at 15:15
• @Giuseppe No, as you're generating the numbers by doing the maths, rather than just placing them into an array/string – caird coinheringaahing Dec 15 '17 at 22:14
• @cairdcoinheringaahing In my opinion that's hardcoding the gamma constant. It doesn't work "in theory" for larger numbers. – user202729 Dec 22 '17 at 12:44
• Chat room – user202729 Dec 22 '17 at 12:45

# 202. Oasis, 50 bytes, A000213

bc+d+111


$s are filler. Try it online! Next Sequence • dagnabbit, I had a Cubix solution all ready, I just needed one pad byte to get to 53 :( – Giuseppe Oct 2 '17 at 23:12 # 209. APL (Dyalog), 100 bytes, A000075 { dims ← 1 + 2 * ⍵ table ← ∘.{+/2 3×⍺ ⍵*2}⍨ ⍳dims uniq ← ∪ (dims*2)⍴ table +/ (××(2*⍵)≥⊢) uniq }  using ⎕IO←0. Try it online! Next sequence • Ugh. I was about to test this. I think this is the theme of this challenge. – NieDzejkob Oct 10 '17 at 12:48 • @NieDzejkob yea, was hit the same way a few times. they should have set some way to reserve spots – Uriel Oct 10 '17 at 12:49 • Yeah, I've seen some other [answer-chaining] question do that. – NieDzejkob Oct 10 '17 at 12:53 # 213. Befunge-98 (PyFunge), 117 bytes, A000079 v v2< * \ \ - did you know that comments in befunge start and end with nothing? 1 >&1\>:| >$.@


Try it online!

Next sequence!

• Wait, I thought it was one of these selfreferential sequences like "OEIS sequences that contain their own index number" – NieDzejkob Oct 10 '17 at 13:57
• lol no meta sequences pls – totallyhuman Oct 10 '17 at 13:58

# 214. Julia 0.4, 383 bytes, A000117

Because of sequence relationships, I've implemented A000013 four times now.

function EulerPhi(n)
x = 0
for i = 1:n
if gcd(i,n) == 1
x = x + 1
end
end
return x
end

function A000013(n)
if n <= 1
return 1
end
x = 0
for d = 1:n
if n/d == n÷d
x = x + (EulerPhi(2*d) * 2^(n/d))/(2*n)
end
end
return x
end

function A000011(n)
return (A000013(n) + 2^(n÷2))/2
end

function A000117(n)
return A000011(2*n)
end


Next Sequence

Try it online!

• ...Dammit, all these n-nacci sequences and I can't answer. ;-; 37 minutes left... – totallyhuman Oct 10 '17 at 14:14
• @icrieverytim I was well on my way with a Funciton tetranacci when you posted yours. Serves you right. – KSmarts Oct 10 '17 at 14:19

# 212. JavaScript (SpiderMonkey), 79 bytes, A000078

a = n => n < 3 ? 0 : n == 3 ? 1 : a(--n) + a(--n) + a(--n) + a(--n)

// balloon


Try it online!

Next sequence.

• @Mr.Xcoder he copypasted the codegolf submission from TIO to edit it later. Common practice if you don't want to get ninjad – NieDzejkob Oct 10 '17 at 13:50
• Give a guy some time. :P – totallyhuman Oct 10 '17 at 13:50
• I was just looking at the code snippet, and it looks like Groovy has already been used twice. – KSmarts Oct 10 '17 at 19:05
• @KSmarts Oops... – totallyhuman Oct 10 '17 at 19:13

load("ratpow")$p(n):=num_partitions(n); q(n):=ratp_dense_coeffs( product(1+x^(2*k-1),k,1,n) ,x)[n]; a(n):=(p(n+2)+3*q(n+3))/2;  Next Sequence Try it online! This uses the first formula on the OEIS page, with a built-in for p and the generating function for q. It's basically the same as the Mathematica code. # 220. Visual Basic .NET (.NET Core), 107 bytes, A000127 Function A000172(n As Integer) As Integer n += 1 Return(n^4 - 6*n^3 + 23*n^2 - 18*n + 24) / 24 End Function  Try it online! Next Sequence Note that the implementation of VB.NET on TIO does not have BigIntegers (I tried it and it wants a .dll) so I can use You can assume that neither the input nor the required output will be outside your languages numerical range, but please don't abuse this by choosing a language that can only use the number 1, for example. • Maple and Mathematica for the next sequence seem to be using a formula not mentioned in the formula section. – NieDzejkob Oct 11 '17 at 14:52 • Why do so many of the sequences' formula sections say G.f. A(x) = Sum_{n>=1} a(n)*x^n = x / Product_{n>=1} (1-x^n)^a(n)? That's a definition of the generating function. It's not helpful. – KSmarts Oct 11 '17 at 15:00 • @KSmarts The first equation does nothing but implicitly saying that the first value is zero and introducing the name a, but the second is unique to this sequence. It allows to incrementally compute the series. If you see it many times maybe that is because A000081 appears so often... – Christian Sievers Oct 11 '17 at 17:38 # 234. Rust, 512 bytes, A000141 fn a(n: i64) -> i64 { let mut ret = 0; for a in !n..-!n { for b in !n..-!n { for c in !n..-!n { for d in !n..-!n { for e in !n..-!n { for f in !n..-!n { if a * a + b * b + c * c + d * d + e * e + f * f == n { ret += 1; } } } } } } } return ret; }  Try it online! Next sequence. Nice byte count, eh? • I know how to code the next sequence, but idk what language to do it in :( – Husnain Raza Oct 23 '17 at 12:08 • @HusnainRaza I posted a bruteforce solution with a broken equivalence checker in Squirrel (the embeddability of Lua, typing of Python and the syntax of C) in The Nineteenth Byte, feel free to salvage stuff. – NieDzejkob Oct 23 '17 at 12:31 • @HusnainRaza I have discovered a truly marvelous demonstration of this proposition that this margin is too narrow to contain. – KSmarts Oct 23 '17 at 14:14 • @NieDzejkob But the equivalence checking is the hard part, isn't it? – KSmarts Oct 23 '17 at 14:17 • @KSmarts yes, but the point is an easy to use language with the boilerplate serving at least as a good syntax example. – NieDzejkob Oct 23 '17 at 14:37 # 238. LOLCODE, 429 bytes, A000089 HAI 1.2 I HAS A INPUT GIMMEH INPUT INPUT IS NOW A NUMBR INPUT R SUM OF INPUT AN 1 I HAS A COUNT ITZ 0 I HAS A INDEX ITZ 1 I HAS A TEMP ITZ 0 IM IN YR LOOP TEMP R PRODUKT OF INDEX AN INDEX TEMP R SUM OF TEMP AN 1 TEMP R MOD OF TEMP AN INPUT BOTH SAEM TEMP AN 0 O RLY? YA RLY COUNT R SUM OF COUNT AN 1 OIC BOTH SAEM INDEX AN INPUT O RLY? YA RLY GTFO OIC INDEX R SUM OF INDEX AN 1 IM OUTTA YR LOOP VISIBLE COUNT KTHXBYE  Next Sequence Try it online! This just directly counts the solutions. None of that Legendre symbol nonsense. • Mathematics is never nonsense. – user202729 Oct 27 '17 at 15:10 • @user202729 That code looks like nonsense to me :P – caird coinheringaahing Oct 27 '17 at 15:10 • @user202729 I just meant that it seems to over-complicate the problem. Finding the divisors of n and computing the product of a modified Legendre symbol of those divisors is not simpler than just counting, imo. – KSmarts Oct 27 '17 at 15:32 • @user202729 Actually... – KSmarts Oct 27 '17 at 16:33 # 240. CHICKEN Scheme, 256 bytes, A000346 (define (factorial x) (cond ((< x 2) 1) (else (* x (factorial (- x 1)))))) (define (choose n k) (cond ((= n 0) 1)(else (/ (factorial n) (* (factorial k) (factorial (- n k))))))) (define (a000346 n) (- (expt 2 (+ 1 (* 2 n))) (choose (+ 1 (* n 2)) (+ n 1))))  Try it online! Next sequence • 2*>U2XmX¹>c- crying +1 though lol, despite making mine no longer matter. – Magic Octopus Urn Oct 27 '17 at 19:18 • Nice bytecount! – NieDzejkob Oct 27 '17 at 19:19 • I hope I will finish my Trefunge program before someone else finds an easier language for this sequence... – NieDzejkob Oct 27 '17 at 20:39 • @NieDzejkob I found a bunch of easier languages. Go to tio.run, deselect "recreational," and you'll get a whole list of them! – KSmarts Oct 27 '17 at 23:08 • @KSmarts actually, this doesn't work. Haskell still shows up on the list. – NieDzejkob Oct 28 '17 at 11:12 # 153. Emojicode, 1344 bytes, A000136 🐋🍨🍇 👴 Find the index of e in the list by comparing the elements with c 🐖🔎e Element c🍇Element Element➡👌🍉➡🍬🚂🍇 🔂i⏩0🐔🐕🍇 🍊🍭c e🍺🐽🐕i🍇🍎i🍉🍉 🍎⚡ 🍉 🍉 🐇☯🍇 👴 Checks whether a permutation is a possible way to fold stamps 🐇🐖🅱p🍨🐚🚂➡👌🍇 🔂k⏩0➖🐔p 1🍇 🔂r⏭🚮k 2➖🐔p 1 2🍇 🍦c🍇a🚂b🚂➡👌🍎😛a b🍉 🍦A🍺🔎p k c 🍦B🍺🔎p r c 🍦C🍺🔎p➕k 1 c 🍦D🍺🔎p➕r 1 c 🍊🎉🎉🎉🎊🎊◀A B◀B C◀C D🎊🎊◀B C◀C D◀D A🎊🎊◀C D◀D A◀A B🎊🎊◀D A◀A B◀B C🍇🍎👎🍉 🍉 🍉 🍎👍 🍉 👴 Iterates over the permutations 🐇🐖🅰n🚂➡🚂🍇 🍦a🔷🍨🐚🚂🐧n 🍦c🔷🍨🐚🚂🐧n 🔂i⏩0 n🍇 🐷a i i 🐷c i 0 🍉 🍮i 0 🍮r 1 🔁◀i n🍇 🍊◀🍺🐽c i i🍇 🍮j 0 🍊😛🚮i 2 1🍇🍮j🍺🐽c i🍉 🍦t🍺🐽a j 🐷a j🍺🐽a i 🐷a i t 🍊🍩🅱☯a🍇🍮➕r 1🍉 🐷c i➕1🍺🐽c i 🍮i 0 🍉🍓🍇 🐷c i 0 🍮➕i 1 🍉 🍉 🍎r 🍉 🍉 🏁🍇 🍊🍦i🚂🔷🔡😯🔤🔤10🍇 😀🔡🍩🅰☯➕1 i 10 🍉 🍉  Try it online! Next sequence! I was going to use something esoteric, but then I changed my mind. Pretty self explanatory, I don't think an explanation is necessary. Note: for inputs larger than 7, you have to specify a heap size larger than 512 MB during the compilation of the Real-Time Engine. For example, use cmake .. -DheapSize=1073741824 for 1 GB. If you run out of heap space, the VM segfaults, probably because someone does not check for NULL after malloc. Edit: make this faster and less memory-hungry. Now I wonder whether the garbage collector is working properly Edit almost 2 months later: this code had to work around a bug in the implementation of the ⏩ type. Now that this bug is fixed and TIO updated, I had to offset the range parameters again. I also managed to add some comments, all while keeping the bytecount the same. • It segfaults for n=7? oookay. – Giuseppe Sep 12 '17 at 0:10 • ... which makes this answer invalid. – pppery Sep 12 '17 at 1:26 • @ppperry "fixed" – NieDzejkob Sep 12 '17 at 5:36 • This isn't at all self-explanatory. – Peter Taylor Sep 12 '17 at 10:31 • @INCOMING Emoji (the stack based language) is definitely esoteric, but Emojicode is object oriented and stuff. Believe it or not, but there is real software written in Emojicode, ~~in contrast to Haskell~~. – NieDzejkob Sep 12 '17 at 12:44 # 249. PicoLisp, 171 bytes, A000904 (de a000904 (n) (cond ((= n 0) 0) ((= n 1) 3) ((= n 2) 13) (T (+ (* (+ n 2) (a000904 (- n 1))) (* (+ n 3) (a000904 (- n 2))) (a000904 (- n 3))) ) ) )  Try it online! next sequence Woo! eleventh page! • Eleventh? I don't see deleted posts (except my own) and I'm on the 9th... – NieDzejkob Nov 7 '17 at 19:02 • @NieDzejkob yeah, the eleventh page if you include all deleted posts. – Giuseppe Nov 7 '17 at 19:37 • "Eleventh page" is not as important as "301 answers". If the 301 number is not counting deleted posts, then "all languages available again". I was actually quite disappointed to see that 301 is counting-deleted. – user202729 Nov 8 '17 at 11:07 • Yay! No formula! – user202729 Nov 8 '17 at 11:08 • @user202729 From Wolfram Mathworld: "The number of self-complementary graphs on n nodes can be obtained from the "graph polynomial" P_n(x) derived form Pólya's enumeration theorem used to enumerate the numbers of simple graphs as P_n(-1)." This is the method that the given Mathematica code uses, because of course Mathematica has a built-in for that. – KSmarts Nov 8 '17 at 14:28 # 157. C (gcc), 376 bytes, A002466 int f(int n) { int i = 0, s[100] = {0}; s[0] = 1; s[1] = 1; s[2] = 2; while (i < 97) { if ((i % 5) == 3) { s[3+i] = s[i] + s[2+i]; } else if ((i % 5) == 4) { s[3+i] = s[1+i] + s[2+i]; } else { s[3+i] = s[i] + s[1+i] + s[2+i]; } i++; } return s[n]; }  It's like an obnoxious Fibonacci! 0-indexed. Next sequence Try it online! The function for this sequence said this: a(1) = a(2) = 1, a(3) = 2, a(5*k+2) = a(5*k+1) + a(5*k-1), a(5*k+3) = a(5*k+2) + a(5*k+1), a(5*k+b) = a(5*k+b-1) + a(5*k+b-2) + a(5*k+b-3) for b=-1,0,1  It's completely unhelpful. However, I noticed that the integers in the sequence were usually the previous three terms added together, but more obnoxious. Here's my work: 1. 1, 1, 2 -> 4 (ok) 2. 1, 2, 4 -> 7 (ok) 3. 2, 4, 7 -> 13 (ok) 4. 4, 7, 13 -> 17 (no) sum does not include second value 5. 7, 13, 17 -> 30 (no) sum does not include first value 6. 13, 17, 30 -> 60 (ok) 7. 17, 30, 60 -> 107 (ok) 8. 30, 60, 107 -> 197 (ok) 9. 60, 107, 197 -> 257 (no) sum does not include second value 10. 107, 197, 257 -> 454 (no) sum does not include first value 11. 197, 257, 454 -> 908 (ok) 12. 257, 454, 908 -> 1619 (ok) 13. 454, 908, 1619 -> 2981 (ok) 14. 908, 1619, 2981 -> 3889 (no) sum does not include second value 15. 1619, 2981, 3889 -> 6870 (no) sum does not include first value  So for each five terms, the last two would be calculated differently. The modulo's and if-statements in the while loop of the code handle that. • Isn't next-seq a PPCG challenge lol – hyper-neutrino Sep 18 '17 at 23:54 • It's a casewise formula. E.g. a(5*k+2) = a(5*k+1) + a(5*k-1) says that if n % 5 == 2 then a(n) = a(n-1) + a(n-3). – Peter Taylor Sep 19 '17 at 6:56 • And this code doesn't calculate it correctly. Input 10 should give 197 and gives 137. – Peter Taylor Sep 19 '17 at 7:00 • Guessing the formula was a very bad idea... should I edit to correct this or make it a new answer? After all, the order is already ruined... @PeterTaylor what do you think? – NieDzejkob Sep 19 '17 at 8:45 • There's also the problem of segfaulting for n > 100 - keep only the last 3 numbers or allocate this array dynamically – NieDzejkob Sep 19 '17 at 9:38 # 255. Perl 5, 454 bytes, A000098 sub part { my$S;
if ($_[1]==0) {$S = 1 } elsif ($_[1] <$_[0]) { $S = 0 } else {$S = part($_[0],$_[1]-$_[0])+part($_[0]+1,$_[1]) }$S;
}

sub partsum {
my @a = (0..$_[0]); my$S = 0;
for my $i (@a) {$S += part(1,$i); }$S;
}

sub A000097 {
my @a = (0..$_[0]//2); my$S = 0;
for my $i (@a) {$S += partsum($_[0]-2*$i);
}
$S; } sub A000098 { my @a = (0..$_[0]//3);
my $S = 0; for my$i (@a) {
$S += A000097($_[0]-3*$i); }$S;
}


Next Sequence

Try it online!

There's a lot of redundant subroutine calls, so memoization would speed this up a lot.

# 257. TI-NSpire CX Basic, 144 bytes, A000562

Define a562(n)=
Func
:If n=4 Then
:  Return 9
:Else
:  Return ((27)/(8))*n^(4)-((135)/(4))*n^(3)+((921)/(8))*n^(2)-((539)/(4))*n
:EndIf
:EndFunc


Next sequence

Uses Plouffe's conjecture mentioned in the OEIS entry, note that this is different than TI-Nspire CAS Basic as they are two different models of calculator. Next sequence hopefully is easy.

This allows the language to be used again before the 300th.

• Ugh, the next sequence is gross. – Engineer Toast Nov 20 '17 at 21:25
• What if the conjecture is false? Don't you need to prove it? – user202729 Nov 21 '17 at 9:55
• The formula a(n) = 27/8n^4 - 135/4n^3 + 921/8n^2 - 539/4n, n>4 does not seem to be labeled as a conjecture. – NieDzejkob Nov 21 '17 at 10:39
• @user202729 alternatively, he can verify the results for n up to a thousand. – NieDzejkob Nov 21 '17 at 10:41

# 263. Visual Basic .NET (.NET Core), 493 bytes, A000091

It is a multiplicative function. Using a simple prime checking function.

Now VB .NET was used twice.

Function IsPrime(p As Integer) As Boolean
For i = 2 To p - 1
If p Mod i = 0 Then Return False
Next
Return True
End Function

Function A000091(n As Integer) As Integer
n += 1
If n = 1 Then Return 1
If n Mod 9 = 0 Then Return 0

Dim ans As Integer = 1
If n Mod 2 = 0 Then ans *= 2
If n Mod 3 = 0 Then ans *= 2
While n Mod 2 = 0
n /= 2
End While
For i = 5 To n
If IsPrime(i) And n Mod i = 0 Then
If i Mod 3 = 1 Then ans *= 2 Else Return 0
End If
Next
Return ans
End Function


Try it online!

Next sequence

I chose a simple sequence. The smallest unused sequence until now is A000099.

• As far as I can tell, A000064 has been used – caird coinheringaahing Nov 24 '17 at 17:21
• @cairdcoinheringaahing Thanks, fixed. (I sorted the snippet by sequence number and there are no A000064. Did something get wrong?) – Colera Su Nov 24 '17 at 23:43

# 215. MATL, 95 bytes, A000383

'this is just a random string for padding aagghhhh need at least 80 chars!'xT6Y"i:"t-5:0)sh]GQ)


Try it online!

Next sequence

'...'x                 string and delete from stack
T6Y"                   push 6 ones
i:"                    iterate user input number of times
t-5:0)sh            dup, index last 6, sum, horzcat
]           end loop
GQ)        copy user input, increment, index (return)

• Sorry @NieDzejkob :( but you couldn't have answered anyway, your hour wasn't up! – Giuseppe Oct 10 '17 at 14:41
• Yeah, right. And you ninjad me by 4 minutes anyway. I just didn't notice your answer and then after posting mine, the page reloaded. – NieDzejkob Oct 10 '17 at 14:44

# 264. PowerShell, 102 bytes, A000493

function A000493($n) {return [math]::floor([math]::sin($n))}



Try it online!

Next sequence.

• We've already had 64 – caird coinheringaahing Nov 24 '17 at 17:20
• ...I looked at the last answer and it said 64. >.> Padding, hang on. – totallyhuman Nov 24 '17 at 17:21
• Actually, there was 95. However, it seems that the MATL submission missed the sequence number in the title, so it isn't shown in the snippet. – Colera Su Nov 24 '17 at 23:46
• @totallyhuman well, we got the shit together :P – caird coinheringaahing Nov 25 '17 at 0:12
• I just noticed that the bytecount of this answer is a palindrome of the bytecount of the other PowerShell answer :) – NieDzejkob Jan 3 '18 at 14:55

# 270. Husk, 103 bytes, A000118

←→-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1+*1=⁰0*±⁰≠*8Σu†ΠṖp⁰*<1%4⁰*32Σu†ΠṖp/4⁰


Try it online!

Next Sequence.

Ignore the madness that precedes the actual code, it’s just fluff to make this 103 bytes.

### How it works

Husk does not have a “divisors” built-in, so (Ḋ has been implemented) this was actually fun to solve.

• First off, it computes the divisors of N using prime factorization (prime factors, powerset, product of each, deduplicate) and sum them up. Then, it multiplies the result by 8.

• After that, it computes the sum of N / 4’s divisors, and multiplies it by 32 if N is divisible by 4, or evaluates the whole thing to 0 otherwise.

• Takes the absolute difference between the above terms.

• For handling the special case of 0, this just multiplies our result by the sign of N, and adds 1 iff N is 0.

To put it simply, it calculates (N==0 ? 1 : 0)+sgn(N)(8σ(N)+32σ(N/4)(N%4==0 ? 1:0)).

• I was just about to post a solution in Actually... – NieDzejkob Nov 30 '17 at 22:00
• @NieDzejkob Oh sorry for ninja’ing again. At least it was nonetrivial for me, Husk doesn’t have a divisor built-in so... – Mr. Xcoder Nov 30 '17 at 22:02
• Ḋ is divisors in Husk – H.PWiz Nov 30 '17 at 23:55
• @H.PWiz It has been added recently right? – Mr. Xcoder Dec 1 '17 at 6:12
• @HusnainRaza I said that I will solve it means I will solve it. Don't push me. – user202729 Dec 7 '17 at 13:46

# 135. Husk, 29 bytes, A000277

*1*1*1*1*1*1*1+5-*2⌊√+5*4⁰*3⁰


Try it online!

Next Sequence.

# 144. Chez Scheme, 68 bytes, A000120

(define(e n)(cond((< n 1)0)((+(e(fx/ n 2))(remainder n 2)))))


Try it online!

Next sequence

• +100 rep if someone does the next one in Beatnik – NieDzejkob Sep 7 '17 at 16:22

# 273. Ohm v2, 123 bytes, A000129

2¬1+³ⁿ1 2¬-³ⁿ-2¬d/¦


Try it online! (note the trailing spaces)

Next Sequence.

I didn't want to nearly-kill the challenge again, so I chose A000123, which isn't that hard.

Implements a(n) = ((1+√2)n - (1-√2)n) / (2√2), rounded to the nearest integer (because there are small floating-point inaccuracies).

• I was working on 6502 asm for 272 when this was posted – Tornado547 Dec 7 '17 at 20:22
• @Tornado547 I feel ya. It's tough to get an answer in when the sequences are so simple, but you'll have lots of chances! – Giuseppe Dec 7 '17 at 20:38

# 276. MATLAB, 188 bytes, A000113

n=input('')+1;
F=factor(n);
psi = @(x) x*prod(1+1./unique(F))-(x<2);
i=sum(F==2);
j=sum(F==3);
if i > 5
i = 3;
else
i = floor(i./2);
end
if j > 1
j = 1;
else
j = 0;
end
psi(n) ./ (2^i*3^j)


Try it online!

Next Sequence

As this is a carefully written polyglot with Octave, it will run on TIO.

Implements the formula with Dedekind's psi function listed in the notes.

Oddly, there's a dead link for transformation groups on this OEIS wiki page and I'm not entirely sure how to count transformation groups!

# 266. UCBLogo, 2572 bytes, A000636

; ------ helper function ------ (unrelated to the problem)

; minimum of two numbers
to min :x :y
output ifelse :x<:y [:x] [:y]
end

; clone an array
to clone :arr
localmake "ans (array (count :arr) (first :arr))
localmake "offset -1+first :arr
repeat count :arr [
setitem (#+:offset) :ans (item (#+:offset) :arr)
]
output :ans
end

; ------ coefficient list manipulators ------

; apply (map binary function)
to ap :func :x :y
localmake "ans arz min count :x count :y
for [i 0 [-1+count :ans]] [
setitem :i :ans (invoke :func item :i :x item :i :y)
]
output :ans
end

; zero-indexing zero array : f(x) = 0
to arz :n
localmake "ans (array :n 0)
repeat :n [setitem #-1 :ans 0]
output :ans
end

; polynomial multiplication
to convolve :x :y [:newsize (count :x)+(count :y)-1]
localmake "ans arz :newsize
for [i 0 [-1+count :x]] [
for [j 0 [min -1+count :y :newsize-:i-1] 1] [
setitem :i+:j :ans (item :i+:j :ans) + (item :i :x) * (item :j :y)
]
]
output :ans
end

; given arr = coefficients of f(x), calculate factor * f(x^n)
to extend :arr :n [:factor 1]
localmake "ans arz (-1+count :arr)*:n+1
repeat count :arr [
setitem (#-1)*:n :ans (:factor*item #-1 :arr)
]
output :ans
end

; calculate :const + :factor * x * p(x)
to shift :p :factor :const [:size 1+count :p]
localmake "ans (array :size 0)
setitem 0 :ans :const    ; 1+...
repeat :size-1 [
setitem # :ans (item #-1 :p)*:factor
]
output :ans

end

; calculate multiplication inverse (1/p(x))
to inverse :p [:n (count :p)]
localmake "one arz :n
setitem 0 :one 1

localmake "p_1 clone :p
setitem 0 :p_1 (-1+item 0 :p_1) ; p_1(x) = p(x) - 1

localmake "q (array 1 0)
setitem 0 :q (1/item 0 :p) ; q(x) = 1/p(0) (coefficient of x^0)

repeat :n [
make "q ap "difference :one (convolve :p_1 :q #)
]

output :q
end

; ------ define functions ------

; calculate r(x) first n coefficients
to r :n
localmake "ans {1}@0
repeat :n [
make "ans (shift (ap "sum ap "sum
convolve convolve :ans :ans :ans ; r[x]^3
convolve :ans (extend :ans 2 3)  ; 3*r[x]*r[x^2]
(extend :ans 3 2)  ; 2 r[x^3]
) 1/6 1 #)
]
output :ans
end

; calculate R(x) first n coefficients
to BigR :n
localmake "rn r :n
output (extend
ap "sum
convolve :rn :rn ; r[x]^2
extend :rn 2     ; r[x^2]
1 0.5)  ; /2
end

; main function
to main :n
localmake "Rx bigR :n+1
localmake "inv_1_xRx inverse shift :Rx -1 1 ; 1 - x*R[x]
output item :n+1 (extend (ap "sum
:inv_1_xRx
convolve
(shift :Rx 1 1)   ; 1 + x*R[x]
(extend :inv_1_xRx 2) ; 1/(1 - x^2 * R[x^2])
) 1 0.5)
end


Try it online! (at Anarchy golf performance checker)

Paste the code there, and then append print main 10 at the end.

Although Logo has been used twice, UCBLogo only once and FMSLogo only once. In other word, programming languages that has multiple versions tend to have more advantage in this challenge. Next time it will probably be Elica.

Next sequence.

• Probably the next answer is "using the recurrence formula in the Mathematica code". I don't like that, if anyone do that please also include formula proof. – user202729 Nov 30 '17 at 15:19
• Sorry for "just using the formula"... but I promise I will add mathematical explanation. – user202729 Nov 30 '17 at 16:00

# 275. Whispers, 113 bytes, A001021

> Input
> 12
>> 2*1
>> Output 3
Rather than add a bunch of spaces,
I think it'd be better to actually have
words.


Try it online!

Next sequence

## How it works

The parser automatically removes lines that don't match any of the valid regexes, meaning that the code that actually gets executes is

> Input
> 12
>> 2*1
>> Output 3


Which is executed non-linearly way (as most Whispers programs are), and runs as follows:

Output ((12) * (Input))


Where * is exponentiation (raising x to the power y)

• What are the rules on using languages newer than the challenge? – KSmarts Dec 7 '17 at 20:28
• @KSmarts Just so long as it isn't specifically designed for this challenge (or violate any other standard loophole), it's the same as posting an answer with a newer language on any other question. – caird coinheringaahing Dec 7 '17 at 21:01
• What is this sorcery? – NieDzejkob Dec 7 '17 at 21:29
• Does this still work if you change acually to actually and remove the duplicate !? – Esolanging Fruit Dec 8 '17 at 4:17
• This language reminds me of LLVM IR... – NieDzejkob Dec 9 '17 at 14:22

# 279. Fortran (GFortran), 2852 bytes, A005692

program beans

integer :: n, first_move, last_move, new_move1, new_move2, turn_count, win_accomplished, cycleq

integer, dimension(270,1000000) :: current_paths, next_paths
integer :: next_path_count, current_path_count, path_iter, move_iter, cycle_iter

first_move = 2*n+1
turn_count = 0
win_accomplished = 0

current_paths(1,1)=first_move
current_path_count=1

do while(.true.)

turn_count = turn_count + 1    !current path length

if (first_move == 1) then
turn_count = 1
exit
end if

next_path_count = 1

do path_iter=1,current_path_count

cycleq = 0
last_move = current_paths(turn_count,path_iter)
!print *,'prince'
!print *,last_move
!print *,'prince'

if (mod(last_move,2)==1)  then
if (last_move>1) then
if (mod(turn_count,2) == 0) then
cycle
end if
end if
end if

if (last_move==1) then
if (mod(turn_count,2) == 0) then
win_accomplished = 1
end if

else if (mod(last_move,2)==0) then
new_move1 = last_move/2

do cycle_iter = 1,turn_count
if (current_paths(cycle_iter,path_iter) == new_move1) then
cycleq=1
end if
end do

if (cycleq == 0) then
do cycle_iter=1,turn_count
next_paths(cycle_iter,next_path_count) = current_paths(cycle_iter,path_iter)
end do
next_paths(turn_count+1,next_path_count) = new_move1
next_path_count = next_path_count + 1
end if

else
new_move1 = 3*last_move + 1
new_move2 = 3*last_move - 1

cycleq=0
do cycle_iter = 1,turn_count
if (current_paths(cycle_iter,path_iter) == new_move1) then
cycleq=1
end if
end do

if (cycleq == 0) then
do cycle_iter=1,turn_count
next_paths(cycle_iter,next_path_count) = current_paths(cycle_iter,path_iter)
end do
next_paths(turn_count+1,next_path_count) = new_move1
next_path_count = next_path_count + 1
end if

cycleq=0
do cycle_iter = 1,turn_count
if (current_paths(cycle_iter,path_iter) == new_move2) then
cycleq=1
end if
end do

if (cycleq == 0) then
do cycle_iter=1,turn_count
next_paths(cycle_iter,next_path_count) = current_paths(cycle_iter,path_iter)
end do
next_paths(turn_count+1,next_path_count) = new_move2
next_path_count = next_path_count + 1
end if

end if

end do

if (win_accomplished==1) then
exit
end if

do path_iter=1,next_path_count-1
do move_iter=1,turn_count+1
current_paths(move_iter,path_iter) = next_paths(move_iter,path_iter)
next_paths(move_iter,path_iter) = 0
end do
end do

current_path_count = next_path_count-1

end do

print *,turn_count-1

end program beans


Try it online!

Next Sequence

I originally wrote a similar program in Python. It properly compiled in Pyon but I wanted to see if I could write it in Fortran first and save Pyon/Python for harder sequences.

The program relies on the fact that if Jack moves to an odd number then the Giant gains control and will be able to use a never-lose strategy. It starts with a the Giant's fist move [n] then enumerates all the possible games until the first win is found which must be the shortest one since moves are added to each possible game pathway once per iteration of the main loop. If Jack loses in one particular game or if the Giant takes control then that particular game pathway is abandoned which helps save on memory and time.

The first term in the sequence doesn't make any sense to me since it isn't a win for Jack but I hard coded it in anyway.

The paper OEIS references helped me understand the sequence. They suggest an algorithm to us on a computer (they calculated the first 525 terms of the sequence by hand) which I didn't use because it seemed a little more difficult to implement but it would probably be faster and much less memory intensive.

Because of memory limitations, the program won't actually work on all the terms but is fine for terms up to at least 119 (n=109). Note that the two arrays declared at the top have 270x10^6 elements. This allows in the algorithm for 10^6 branches of possible game paths of length 270 moves. None of the first 1000 terms are bigger than 263 so this is still valid for the challenge.

The next sequence (terms in the continued fraction of Eulers constant) looks pretty hard, but maybe that's just because I don't know how to do it of the top of my head. I promise I didn't engineer my byte-count to pick this, it's just what I ended up with.

Edit: It seems calculating the terms doesn't seem too hard once you have the actual constant (which is irrational [edit: apparently this is actually not known]). Here are some resources:

• 119 (n=109) Huh? – user202729 Dec 15 '17 at 6:06
• NOTE There has already been a deleted answer that hardcodes. Don't do this again if you don't want downvotes. – user202729 Dec 15 '17 at 6:11
• @user202729 Haha sorry to disappoint you. I know what a continued fraction is just didn’t know how to calculate it off the top of my head. I agree the next one isn’t that hard – dylnan Dec 15 '17 at 13:14
• @Giuseppe it kind of hardcodes the sequence to get a number from which you can compute the sequence. Don't you think that's a little pointless? – NieDzejkob Dec 15 '17 at 21:22
• numberworld.org/y-cruncher/internals/formulas.html – politza Dec 16 '17 at 8:56

# 283. Ohm v2, 384 bytes, A000126

³4+ý³-2-


Try it online!

Next Sequence. (This one is trivial, the hexagonal numbers!)

If this were code golf, I could solve this in 6 bytes: 4+ýa‹‹.

This one was really just Fibonacci(N + 4) - N - 2.

• Please let me do the next one in Hexagony! – NieDzejkob Dec 24 '17 at 14:41
• Wait, I still need to wait 45 minutes... I'll try anyway – NieDzejkob Dec 24 '17 at 14:41

# 287. Scratch 2, 7437 Bytes, A001118

Try it online

Here is the text version of the full program.

Below is the portion of the program that represents the code blocks in the image. The full text is much longer, dealing with things irrelevant to this challenge.

        "scripts": [[275.8,
75.2,
[["procDef", "Power %n %n", ["Base", "exponent"], [1, 1], false],
["setVar:to:", "presult", "1"],
["doRepeat",
["getParam", "exponent", "r"],
[["setVar:to:", "presult", ["*", ["readVariable", "presult"], ["getParam", "Base", "r"]]]]]]],
[539.1,
73.2,
[["procDef", "Binomial %n %n", ["a", "b"], [1, 1], false],
["call", "FactLoop %n", ["getParam", "a", "r"]],
["call", "FactLoop %n", ["getParam", "b", "r"]],
["call", "FactLoop %n", ["-", ["getParam", "a", "r"], ["getParam", "b", "r"]]],
[286.7,
244,
[["procDef", "FactLoop %n", ["n"], [1], false],
["setVar:to:", "count", ["getParam", "n", "r"]],
["setVar:to:", "result", "1"],
["doUntil",
["changeVar:by:", "count", -1]]]]],
[44,
71,
[["whenGreenFlag"],
["setVar:to:", "sum", 0],
["setVar:to:", "i", 0],
["doRepeat",
5,
[["call", "Power %n %n", -1, ["readVariable", "i"]],
["call", "Binomial %n %n", 5, ["readVariable", "i"]],
["changeVar:by:", "i", 1]]],


Next Sequence: Inverse Moebius transformation of triangular numbers

• +1 for using Scratch and for giving us an easy sequence. Solved in Swift 4 :) – Mr. Xcoder Dec 25 '17 at 20:01
• Scratch is verbose. (depends on how is the number of bytes counted) – user202729 Dec 26 '17 at 14:02

# 290. Hy, 337 bytes, A000149

(import decimal)
(setv ctx (.getcontext decimal))
(setv ctx.prec 500)
(setv iterations 2800)

(defn factorial [n]
(reduce *
(range 1 (inc n))
1))

(defn exp [n series-terms]
(sum
(list-comp
(/ (decimal.Decimal (** n k)) (factorial k))
(k (range series-terms)))))

(defn A000149 [n]
(int (exp n iterations)))


Next sequence--here's a nice easy one so you can break out the obscure esolangs. ;^)

We implement the exponential function by taking partial sums of its MacLaurin series: e^n = Sum[k=0..inf] n^k/k!. For values far away from 0, the series converges more slowly, so we need to calculate a lot of terms to get an accurate result. Trial and error showed that 2800 terms was sufficient for n=1000. The decimal module provides arbitrary-precision arithmetic; 500 significant digits gets us up to n=1000 easily.

# 292. Gaia, 132 bytes, A000130

ọ0D¦1C1=
┅f↑¦Σ2÷


Try it online!

Next sequence.

The next one should not be too hard (there is a näive approach to generate all the integer partitions, and for each partition P check if P is of length 5 and that each element in P is a square :P). I have solved this in Pyth first, then got a much more efficient technique, which I then ported to Gaia.

## How it works?

ọ0D¦1C1= | Helper function.

ọ        | Compute the incremental differences (deltas).
0D¦     | For each, calculate the absolute difference to 0 (absolute value).
1C   | Count the 1's.
1= | Return 1 if the result is equal to 1, 0 otherwise.

┅f↑¦Σ2÷  | Main function. Let N be the input.

┅        | The integers in the range 1 ... N.
f       | Compute the permutations.
↑¦     | For each permutation, apply the above helper function called monadically.
Σ    | Sum.
2÷  | Halve and implicitly display the result.

• This one has useful and easy to calculate g.f., but note that (1)² and (-1)² are different ways. You can implement FFT if you like. – user202729 Dec 31 '17 at 13:51