As of 13/03/2018 16:45 UTC, the winner is answer #345, by Scrooble. 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:

1. NieDzejkob - 41 answers

2. KSmarts - 30 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.


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.


As with most questions, please format your answer like this

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


[next sequence](link)

*anything else*


  • 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.

Answer chain snippet

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>

  • \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$ – Dennis Oct 31 '17 at 2:49
  • \$\begingroup\$ 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? \$\endgroup\$ – NieDzejkob Nov 21 '17 at 15:15
  • 1
    \$\begingroup\$ @Giuseppe No, as you're generating the numbers by doing the maths, rather than just placing them into an array/string \$\endgroup\$ – caird coinheringaahing Dec 15 '17 at 22:14
  • 2
    \$\begingroup\$ @cairdcoinheringaahing In my opinion that's hardcoding the gamma constant. It doesn't work "in theory" for larger numbers. \$\endgroup\$ – user202729 Dec 22 '17 at 12:44
  • 6
    \$\begingroup\$ Chat room \$\endgroup\$ – user202729 Dec 22 '17 at 12:45

346 Answers 346


294. Swift 3, 218 bytes, A000431

import Foundation

infix operator **
func **(_ base: Int, _ exponent: Int) -> Int{
    return Int(pow(Double(base), Double(exponent)))

func A000431(_ n: Int) -> Int {
	return ((4 ** Int(n)) - ((2**(n+1)) * n)) / 8

Try it online!

Next Sequence.

Note that I have previously used Swift 4 (twice), but this time I used Swift 3. This version thankfully works in both Swift 3 and Swift 4, so this can be tested online.


296. Pyt, 161 bytes, A000133


All of those spaces at the end are padding.

Try it online!

Next Sequence!


289. Pyt, 149 bytes, A000186


The program is a port of the Mathematica algorithm listed on the OEIS page.

Most of the work done is managing the stack.

Try it online!

Next sequence: floor(e^n)

  • \$\begingroup\$ Is there an (online) interpreter somewhere we can use to verify this solution? \$\endgroup\$ – Giuseppe Dec 29 '17 at 21:52
  • \$\begingroup\$ Unfortunately, no. But I can post the testing file I used to the github page. It'll be pyttesting.py. Yes, I know I haven't implemented separate files for holding code - I'll get to that very soon. \$\endgroup\$ – mudkip201 Dec 29 '17 at 22:01
  • \$\begingroup\$ Actually, I've now implemented an interpreter that takes a file as a command-line argument \$\endgroup\$ – mudkip201 Dec 29 '17 at 23:00
  • \$\begingroup\$ @mudkip201 If you'd like me to add Pyt to TIO, let's meet in talk.tryitonline.net. \$\endgroup\$ – Dennis Dec 31 '17 at 20:16

301. Trefunge-98 (PyFunge), 165 bytes, A002407

        v\$\+#-1_z#;$.@;:R$;^  +2;wOO%#;_v
        >  1^1                  $$<      <
Yup, Trefunge. Don't worry, I'm not insane.

Try it online!

Next sequence!


302. MOO, 135 bytes, A000165

return 2 ^ args[1]* $sysobj.sysobj.sysobj.sysobj.sysobj.sysobj.sysobj.sysobj.sysobj.sysobj.sysobj.sysobj.math_utils:factorial(args[1]);

The $sysobj.sysobj.sysobj.sysobj. is pure padding to avoid a duplicate sequence; return 2 ^ args[1]* $math_utils:factorial(args[1]) would do the same thing.

Next sequence

  • \$\begingroup\$ Interesting way to do padding... \$\endgroup\$ – NieDzejkob Jan 6 '18 at 14:37
  • \$\begingroup\$ Wait, is it this MOO? \$\endgroup\$ – NieDzejkob Jan 6 '18 at 14:43
  • \$\begingroup\$ this \$\endgroup\$ – pppery Jan 6 '18 at 17:31

222. Julia 0.4, 110 bytes, A000670

function A000670(n)
 S = 0
 for k = 0:n
  for j = 0:k
   S = S + (-1)^(k-j)*binomial(k,j)*j^n

Try it online!

Next sequence

Implements the formula found on wikipedia to compute a(n) as a sum of binomial coefficients. I suppose I could have implemented this in another language like Racket or something but whatever. Next seq is the Bell numbers, this sequence is the ordered Bell numbers which I find amusing (since they're out of order).


137. Squirrel, 701 bytes, A000232

function A000232(index) {
local GBTriangle = [[]]
local numbers = []

for(local i=1; i<index*index*index; i++) numbers.append(i);

// Generate primes with Sieve of Sundaram
for(local i=1; i<numbers.len(); i++) {
  for(local j=i; i+j+2*i*j<numbers.len(); j++)
for(local i=0; i<numbers.len(); i++) {

// Build the triangle
for(local i=1; i<=index; i++) {
  for(local a=1; a<GBTriangle[i-1].len(); a++) {
    GBTriangle[i].append( abs( GBTriangle[i-1][a] - GBTriangle[i-1][a-1] ))

for(local i=0; i<GBTriangle[index-1].len(); i++) {
    return i;


Try it Online!

Next Sequence


132. Java (OpenJDK 9), 903 bytes, A000116

import java.util.*;
import java.lang.Math;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int input = in.nextInt();
        if(input<=0) System.out.print(1);
        else System.out.print(A000013(2*input));

    public static int A000013(int n) {  // Uses the formula from the OEIS page
        double result = 0;
        for(int d = 1; d<=n; d++) {
            if(n%d==0) {
                double t = totient(2*d);
                double b = Math.pow(2,n/d);
                result += (t*b)/(2*n);
        int r = (int) result;
        return r;

    public static int totient(int n) {  // Follows the definition of Euler's Totient
        int count = 0;
        for(int i = 1; i<n; i++) {
            if(GCD(n,i)==1) count++;
        return count;

    public static int GCD(int a, int b) {  // Uses Euclid's Algorithm for GCD
        if(a<b) {
            if(b%a==0) return a;
            return GCD(b%a, a);
        if(a%b==0) return b;
        return GCD(a%b, b);


Try it online!

Next Sequence

I thought I ought to do this one, since it re-implements A000013 and I did that one in the first place.


326. Lua, 205 bytes, A000385

function Sgm(n)D=0 for d=1,n do if n%d<1then D=D+d end end return D end
function Sum(a,b,f)S=0 for k=a,b do S=S+f(k)end return S end
function Seq(n)return Sum(1,n,function(k)return Sgm(k)*Sgm(-~n-k)end)end

334. C (tcc), 157 bytes, A000219

Sigma_2(n){int s=0;for(int d=0;++d<=n;n%d||(s+=d*d));return s;}
A000219(n){if(!n)return 1;int s=0;for(int k=0;++k<=n;s+=A000219(n-k)*Sigma_2(k));return s/n;}

341. Physica, 803 bytes, A000206

Func Divisors(number: int) – list:
    Return Filter[->divisor: number % divisor == 0; Range[1; number]]

Func GCD(a: int; b: int) – int:
    Return Element[Filter[->number: a % number == b % number == 0; Range[1;Min[{a; b}]]]; 0]

Func EulerPhi(number: int) – int:
    Return Length @ Filter[->a: GCD(a; number) == 1; Range[1; number]]

Func A000013(number: int) – int:
    Return Sum[Map[-> d: (EulerPhi[2 * d] * 2 ^ (number / d)) / (2 * number); Divisors[number]]]

Func A000011(number: int) – int:
    Return (A000013(number) + 2 ^ (number / 2)) / 2

Func A000206(number: int) – int:
    If number == 0:
        Return 1
    If number % 2 == 1:
        Return A000011(2*number) / 2
        Return (A000011(2*number) + A000011(number) + 4^(number/2 - 1) - 2^(number/2 - 1)) / 2

Next Sequence.


As Physica is not available on TIO yet, here's a GIF:

Usage GIF

How it works?

OEIS states that this is equivalent to the even orbits of binary necklaces of length 2n under Dn x Sn, and so its formula is a(n) = (A000011(2n) + A000011(n) + 4n/2-1 - 2n/2-1) / 2 for even values of n and a(n) = A000011(2n) / 2 if n is odd, with n for non-null values of n, with a(0) = 1. Diving a bit deeper in OEIS, we find that A000011(n)=(A000013(n)+2⌊n / 2⌋) / 2. Using the formula for A000013, the closed-form of A000011 becomes:

     A000011 closed form

Hence the sequence I implement becomes:

     A000206 – odd n

When n ≡ 1 (mod 2), else:

A000206 – even n


343. Hodor, 382 bytes, A000164

HoDoRHoDoR hodor?!? 000164(HODOR? ) {
  $HODOR: HODOR = 0;
  HODOR{} (o=0; o<=HODOR? ; o++) {
    HODOR{} (d=0; d<=o; d++) {
      HODOR{} (r=0; r<=d; r++) {
        if(HODOR... HODOR hodor. h.HODOR. oHODOR!? (o,2)+HODOR... HODOR hodor. h.HODOR. oHODOR!? (d,2)+HODOR... HODOR hodor. h.HODOR. oHODOR!? (r,2)==HODOR? ) {
          HODOR +=1;    }



  • 2
    \$\begingroup\$ This doesn't work in the TIO link for me. It produces h is not defined error \$\endgroup\$ – caird coinheringaahing Feb 27 '18 at 17:43
  • 1
    \$\begingroup\$ @cairdcoinheringaahing I had to change it to get a valid byte count, and I guess I missed something. It's fixed now. Um, I mean, Hodor. \$\endgroup\$ – KSmarts Feb 27 '18 at 18:44

89. PowerShell, 201 bytes, A000386

function f($m){if($m -lt 1){return 1};1..$m|%{$a=[bigint]1}{$a*=$_}{$a}}
function A000386($n){if($n -le 2){return 0}3..$n|%{$b=[bigint]0}{$b=(f($_-3))*(f($n+$_-3))/(f($n-$_))/(f(2*$_-6))/(f 3)-$b}{$b}}

Online test suite

Next Sequence


Pretty straightforward: the sequence has the formula

$$A(n) = \sum_{j=3}^n (-1)^{n-j} (j-3)! \binom{n+j-3}{n-j,2j-6,3}$$

obtained via some algebraic manipulation from the description in A058057. There are a couple of tricky bits:


produces a range from x to y, but it counts down if y < x, which is not what I want. That's why both functions have special cases.


is an abbreviated foreach loop. In more familiar pseudocode it might be

for $_ = x to y

337. Mathematica 11 (Wolfram Language), 154 bytes, A000159

A000159[n_] := CoefficientList[ Sum[ 2 * (n+3) / (2 * (n+3)-k) * (2 * (n+3)-k)! / (k! * (2 * (n+3)-2 * k)!) * (n+3-k)! * (x-1)^k , {k,0,n + 3}] ,x] [[4]];

Try it online!

Next Sequence

  • 1
    \$\begingroup\$ Note that the next sequence is finite as an "erroneous version of A003713" so hard-coding is allowed. Perhaps the next solver could use a more difficult-to-use language? \$\endgroup\$ – Giuseppe Feb 22 '18 at 17:44
  • \$\begingroup\$ You should probably add your answer's chain number as well as a link to the sequence you are implementing to comply with the question's rules. \$\endgroup\$ – Jonathan Frech Feb 22 '18 at 18:51
  • 2
    \$\begingroup\$ @Giuseppe Done, I just used a useless language :P \$\endgroup\$ – Mr. Xcoder Feb 22 '18 at 20:21

339. ><>, 209 bytes, A000287

vv?)4:-5<>0n; v<v<v<
> 1-}r>:?v~n; @+*}@+
&&    ~  1    :@@:@4
~5    ^$-<    !^<^<*

Try it online!

Next Sequence

This is the chain's third answer in ><>, meaning it can't be used again until we hit answer #450.

The next sequence should be pretty easy if you use a language with trig and rounding built in.


342. 05AB1E, 164 bytes, A000803

2‹i0,q}3‹i8,q}0 0 8)I2-FDO4-¸«¦D}θ,                                                                                                                                 

Try it online!

Next sequence: A000164 - Partition of squares again

129 spaces padded after the last command.


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.