110
\$\begingroup\$

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:

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.

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

As with most questions, please format your answer like this

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

`code`

[next sequence](link)

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

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>

\$\endgroup\$
13
  • \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$
    – Dennis
    Commented Oct 31, 2017 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\$
    – Maya
    Commented Nov 21, 2017 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\$ Commented Dec 15, 2017 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\$
    – DELETE_ME
    Commented Dec 22, 2017 at 12:44
  • 6
    \$\begingroup\$ Chat room \$\endgroup\$
    – DELETE_ME
    Commented Dec 22, 2017 at 12:45

407 Answers 407

1
\$\begingroup\$

288. Swift 4, 186 bytes, A007437

func divisors(_ n: Int) -> [Int]{
	return Array(1...n).filter{n % $0 < 1}
}

func A007437(_ n: Int) -> Int{
	var summ = 0
	for i in divisors(n + 1){
		summ += i*(i+1)/2
	}
	return summ
}

Try it online!

Next Sequence: Number of 3 by n Latin rectangles in which the first row is in order.

\$\endgroup\$
1
\$\begingroup\$

291. Whispers, 130 bytes, A000337

> Input
> 1
> 2
>> 1-2
>> 3*1
>> 4×5
>> 6+2
>> Output 7
As usual, padding is required
to make this a valid answer
Whispers rules!

Try it online!

Next sequence

\$\endgroup\$
1
\$\begingroup\$

293. Commodore 64 BASIC, 431 bytes, A000132

10 R=0
20 INPUT N
30 FOR A=0 TO FLOOR(SQR(N))
40 F=N-A*A
50 FOR B=0 TO FLOOR(SQR(F))
60 G=F-B*B
70 FOR C=0 TO FLOOR(SQR(G))
80 H=G-C*C
90 FOR D=0 TO FLOOR(SQR(H))
100 L=H-D*D
110 E=FLOOR(SQR(L))
120 IF E*E<>L GOTO 200
130 Z=1
140 IF A<>0 THEN Z=Z*2
150 IF B<>0 THEN Z=Z*2
160 IF C<>0 THEN Z=Z*2
170 IF D<>0 THEN Z=Z*2
180 IF E<>0 THEN Z=Z*2
190 R=R+Z
200 NEXT D
210 NEXT C
220 NEXT B
230 NEXT A
240 PRINT R

Next sequence!

Sorry, but no TIO link this time. This will have to do:

an animated GIF

(bytecount measured according to this meta post)

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

296. Pyt, 161 bytes, A000133

←ĐĐĐ1⇹1⇹««⇹1⇹«⁻⇹3Ș⁻1⇹«⁺1⇹«*+⇹⁺1⇹«÷                                                                                                                               

All of those spaces at the end are padding.

Try it online!

Next Sequence!

\$\endgroup\$
1
\$\begingroup\$

289. Pyt, 149 bytes, A000186

←Đ000`ŕ4ȘĐ4ȘĐĐĐ5ȘĐĐ5Ș↔⇹5Ș6Ș8Ș3Ș6Ș4Ș⇹3Ș↔⁺3*~4Ș-+~ĐĐ1~⇹^4ȘÅĐ3Ș⇹+⁻ŘΠ⇹↔Đ↔9Ș↔!3Ș⇹3Ș*⇹!÷*3ȘĐ2⇹^⇹!3Ș4Ș⇹÷*⇹Đ0≥*!*+⇹Đ3Ș⇹⁻3Șłŕ⇹ŕ↔Đ↔⇹3Ș⇹3ȘĐ3Ș⇹⁻Đ5Ș4Ș-3Ș⇹łŕ3Ș↔ŕƥĉ


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)

\$\endgroup\$
4
  • \$\begingroup\$ Is there an (online) interpreter somewhere we can use to verify this solution? \$\endgroup\$
    – Giuseppe
    Commented Dec 29, 2017 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
    Commented Dec 29, 2017 at 22:01
  • \$\begingroup\$ Actually, I've now implemented an interpreter that takes a file as a command-line argument \$\endgroup\$
    – mudkip201
    Commented Dec 29, 2017 at 23:00
  • \$\begingroup\$ @mudkip201 If you'd like me to add Pyt to TIO, let's meet in talk.tryitonline.net. \$\endgroup\$
    – Dennis
    Commented Dec 31, 2017 at 20:16
1
\$\begingroup\$

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

"HTRF"4($$&1>::1+::**\::**-3>::*2Pv
        v\$\+#-1_z#;$.@;:R$;^  +2;wOO%#;_v
        >  1^1                  $$<      <
Yup, Trefunge. Don't worry, I'm not insane.

Try it online!

Next sequence!

\$\endgroup\$
1
\$\begingroup\$

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

\$\endgroup\$
3
  • \$\begingroup\$ Interesting way to do padding... \$\endgroup\$
    – Maya
    Commented Jan 6, 2018 at 14:37
  • \$\begingroup\$ Wait, is it this MOO? \$\endgroup\$
    – Maya
    Commented Jan 6, 2018 at 14:43
  • \$\begingroup\$ this \$\endgroup\$ Commented Jan 6, 2018 at 17:31
1
\$\begingroup\$

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
  end
 end
S
end

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

\$\endgroup\$
1
\$\begingroup\$

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++)
    numbers[i+j+2*i*j]=0;
}
for(local i=0; i<numbers.len(); i++) {
  if(numbers[i]>0)
    GBTriangle[0].append(2*numbers[i]+1);
}

// Build the triangle
for(local i=1; i<=index; i++) {
  GBTriangle.append([])
  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++) {
  if(GBTriangle[index-1][i]>2)
    return i;
}

}

Try it Online!

Next Sequence

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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
\$\endgroup\$
1
\$\begingroup\$

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;}
\$\endgroup\$
1
\$\begingroup\$

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

\$\endgroup\$
3
  • 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
    Commented Feb 22, 2018 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\$ Commented Feb 22, 2018 at 18:51
  • 2
    \$\begingroup\$ @Giuseppe Done, I just used a useless language :P \$\endgroup\$
    – Mr. Xcoder
    Commented Feb 22, 2018 at 20:21
1
\$\begingroup\$

339. ><>, 209 bytes, A000287

0i:0)?!va{*$"0"-+00.
:{6401~<vv?(6
vv?)4:-5<>0n; v<v<v<
> 1-}r>:?v~n; @+*}@+
&&    ~  1    :@@:@4
~5    ^$-<    !^<^<*
>>:32,*3!1-@@:}*@:8^
!v+3*2:@+@@*}<>f2,*v
?>@@:}*@@+$:v^:@@+6<
 v@{@{$,@$+4<
^>{@{@1+:&:&)

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.

\$\endgroup\$
1
\$\begingroup\$

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
    Else:
        Return (A000011(2*number) + A000011(number) + 4^(number/2 - 1) - 2^(number/2 - 1)) / 2

Next Sequence.

Demo

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

\$\endgroup\$
1
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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;    }
      }
    }
  }
  HODOR:: HODOR ;
}

Hodor!

Hodor.

\$\endgroup\$
2
  • 2
    \$\begingroup\$ This doesn't work in the TIO link for me. It produces h is not defined error \$\endgroup\$ Commented Feb 27, 2018 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
    Commented Feb 27, 2018 at 18:44
1
\$\begingroup\$

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

Dissection

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:

x..y

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.

x..y|%{foo}{bar}{baz}

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

foo
for $_ = x to y
  bar
baz
\$\endgroup\$
1
\$\begingroup\$

347. Pure, 824 bytes, A003780

using system;
arr = [0L,0L,0L,0L,0L,296L,0L,0L,0L,70420L,0L,0L,0L,16391166L,0L,0L,0L,3816021084L,0L,0L,0L,888375830566L,0L,0L,0L,206814474641944L,0L,0L,0L,48146529005876746L,0L,0L,0L,11208539472498838244L,0L,0L,0L,2609354391828066201746L,0L,0L,0L,607459192887167645884388L,0L,0L,0L,141416847085185500394182672L,0L,0L,0L,32921922778799648796216249818L,0L,0L,0L,7664242427921761934124201980862L,0L,0L,0L,1784240015038927382237215443432910L];
A003780 n = 262 * A003780(n-4) - 7125 * A003780(n-8) + 78668 * A003780(n-12) - 581608 * A003780(n-16) + 2138065 * A003780(n-20) - 5215246 * A003780(n-24) + 16969316 * A003780(n-28) - 43146455 * A003780(n-32) + 39514076 * A003780(n-36) + 7628882 * A003780(n-40) - 6116529 * A003780(n-44) + 23336 * A003780(n-48) - 2876 * A003780(n-52) + 64 * A003780(n-56) if n > 57;
= arr!n otherwise;

Try it online!

This code assumes the recursion given in OEIS is correct.

This is the first time I use pure, so I hope I didn't do anything wrong.

Next sequence.

\$\endgroup\$
6
  • \$\begingroup\$ Random unused language: Prolog \$\endgroup\$ Commented Dec 30, 2020 at 20:36
  • \$\begingroup\$ I’m not familiar with Pure, but I take it arr isn’t a hard coding of the output? Also, how does this take input? \$\endgroup\$ Commented Dec 30, 2020 at 21:07
  • \$\begingroup\$ It's a function. I accidentally made the input part of the code, let me fix that \$\endgroup\$ Commented Dec 31, 2020 at 4:07
  • \$\begingroup\$ Is it good now? \$\endgroup\$ Commented Dec 31, 2020 at 4:15
  • \$\begingroup\$ @cairdcoinheringaahing according to the recursion given in here, it is possible to get all values of the sequence using the first 58 values, and the recursion I defined for values bigger than 57 \$\endgroup\$ Commented Dec 31, 2020 at 4:17
1
\$\begingroup\$

352. MathGolf, 197 bytes, A000178

╤!ε*

"
╤     # Push a list in the range [-n,n]
 !    # Get the factorial of each, where the negative numbers become 1
  ε*  # Reduce the list by multiplying (a.k.a. take the product of the list)";

Try it online.

Next sequence: A000197.

Explanation:

A000178 is the formula: \$a(n) = \prod_{i=0}^ni!\$

I've already put the explanation in the program itself, wrapped in a string which we discard with ; (after which MathGolf outputs the entire stack joined together as result). The additional newlines for readability are no-ops.

The next sequence A000197 is coincidentally also related to factorials: \$a(n)=(n!)!\$

\$\endgroup\$
1
\$\begingroup\$

354. 05AB1E (legacy), 195 bytes, A000260

4*>DI>csI<c9*-1MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM

Although 05AB1E is banned currently, the legacy version nor 2sable aren't, which are predecessors. 2sable and the legacy version both use a Python backend and the latest 05AB1E uses an Elixir backend. Some of the builtins are also fairly different between the three versions, although this program would act the same in the new and legacy versions of 05AB1E (it fails in 2sable, though).

Try it online or verify the first [0,20] test cases.

Next sequence: A000195. (I just picked a fairly easy one.)

Explanation:

I use the following formula to implement A000260:

$$a(n)=\binom{4n+1}{n+1} - 9\times\binom{4n+1}{n-1}$$

4*          # Multiply the (implicit) input-integer by 4
  >         # Increase it by 1
   D        # Duplicate it
    I>      # Push the input+1
      c     # Binomial coefficient of input*4+1 and input+1
   s        # Swap so the duplicated input*4+1 is at the top again
    I<      # Push the input-1
      c     # Binomial coefficient of input*4+1 and input-1 as well
       9*   # Multiply this by 9
         -  # And subtract it from the earlier number
            # (this is the correct result, except for a(0)=-8)
1           # Push a 1 to the stack
 M          # Push a copy of the largest value on the stack
            # (implicitly output the top of the stack as result)

The additional M do the same, so are essentially no-ops.

\$\endgroup\$
1
\$\begingroup\$

357. Julia 1.0, 167 bytes, A000703

function A000703(n)
    N = 24n
    for i in Iterators.countfrom(5)
        a = 2i
        a -= 7
        a *= a
        a -= 1
        a > N && return i-1
    end
end

Try it online!

the reference implementation was floor((7+sqrt(1+24*n))/2), which is a bit too easy and not enough characters, so I only used simple operators (*, -, >)

Next sequence if mathematica can compute besselk, hopefully anyone can

\$\endgroup\$
1
  • 1
    \$\begingroup\$ BesselK satisfies a simple recurrence relation: \$K_{n+1}(x)=K_{n-1}(x)+\frac{2n}{x}K_n(x)\$. But floating-point error is a problem. I tried this formula, storing the first two terms with 64-bit floating-points. Only the first 20 terms are correct. That is enough for 32-bit integers. So we need a language that uses 64-bit floating-points but 32-bit integers. \$\endgroup\$
    – alephalpha
    Commented Nov 12, 2021 at 16:09
1
\$\begingroup\$

359. MOO, 169 bytes, A000304

number = args[1];
if (number < 4)
  return number;
else
  firstnum = this:(verb)(number - 1);
  secondnum = this:(verb)(number - 2);
  return firstnum * secondnum;
endif

It's getting kind of annoying that all of the short bytecounts are used up, and you have to deliberately bowl to make an answer for the easy sequences. I tried to make it not look obviously bloated, and think I did a good job.

Similar to the previous answer, this sequence grows very fast and the code can only handle up to A(9) before integer overflow occurs.

There's been some rumbling about making the programming language support 64-bit-integers, but nothing's happened yet.

In case anyone cares, return (n=args[1])<4?n|this:(v=verb)(n-1)*this:(v)(n-2); is a 56-byte golfed version (although it could probably be golfed even further if I spent more than a few minutes on it).

Next sequence

Interestingly, the next sequence also grows very fast.

\$\endgroup\$
1
\$\begingroup\$

360. Zephyr, 215 bytes, A000169

`#-
    OEIS  A000169
    Number of labeled rooted trees with n nodes: n^(n-1).
-#`

input num as Integer

set res to 1
set cnt to 1

while cnt < num
    set cnt to cnt + 1
    set res to res * num
repeat

print res

Try it online!

Next sequence!

Interestingly, this is the first language here that starts with Z.

\$\endgroup\$
1
\$\begingroup\$

365. Sass, 207, A002534

@function a002534($n) {
    @if $n < 0 {
        @return -1;
    }
    @if $n == 0 {
        @return 0;
    }
    @if $n == 1 {
        @return 1;
    }
    @return 2*a002534($n - 1) + 9 * a002534($n - 2);
}

Next sequence!

Try it here:

let sassCode = "@function a002534($n) {\n" +
"    @if $n < 0 {\n" +
"        @return -1;\n" +
"    }\n" +
"    @if $n == 0 {\n" +
"        @return 0;\n" +
"    }\n" +
"    @if $n == 1 {\n" +
"        @return 1;\n" +
"    }\n" +
"    @return 2*a002534($n - 1) + 9 * a002534($n - 2);\n" +
"}";

function sassFunctionCallCode(n) {
  return '.answer::after { content: "" + a002534(' + n + '), }'
}

const styleElement = document.createElement('style');
document.head.append(styleElement);


document.getElementById('compile').onclick = function() {
  const result = Sass.compile(sassCode + sassFunctionCallCode(document.getElementById('input').value), function(result){
    styleElement.textContent = result.text;
  });
}

document.getElementById('length').textContent = "The Sass code has length " + sassCode.length + ".";
<script src="https://cdnjs.cloudflare.com/ajax/libs/sass.js/0.9.12/sass.sync.min.js"></script>

<input id="input" type="number" value="4" />
<button id="compile">Compile</button>

<div class="answer">The answer is:&nbsp;</div>

<div id="length"></div>

\$\endgroup\$
1
\$\begingroup\$

377. Kitten, 258 bytes, A000235

define a000235 (Int32 -> Int32):
  0 0 0 0 1 a000235_tailrec

define a000235_tailrec (Int32, Int32, Int32, Int32, Int32, Int32 -> Int32):
  -> n, a, b, c, d, e;
  if (n = 0):
    b
  else:
    (n - 1) b c d e (a + b + -3 * c + -1 * d + 3 * e) a000235_tailrec

Next sequence!

Kitten is a statically typed concatenative language.

The formula for this sequence is \$a(0)=a(1)=a(2)=0\$, \$a(3)=1\$, \$a(n)=3a(n-1)-a(n-2)-3a(n-3)+a(n-4)+a(n-5)\$.

\$\endgroup\$
1
  • \$\begingroup\$ Really cool to see a Kitten answer! Too bad it never saw a proper release; I've been wanting to try it. \$\endgroup\$
    – chunes
    Commented Jun 20, 2022 at 10:59
1
\$\begingroup\$

380. Red, 255 bytes, A000180

Red [
    Title: "OEIS A000180"
    Author: "chunes"
]

factorial: function [n][
    product: 1
    repeat i n [
        product: product * i
    ]
    product
]

A000180: function [n][
    to-integer round 3 ** n * (factorial n) / exp 0.333333333333333
]

Try it online!

Next sequence!

\$\endgroup\$
1
\$\begingroup\$

381. Desmos, 179 bytes, A000255

a ( n_{nnnnnnnnnnnnnnnnnnnnnnnnnn} ) = \sum_{k = 0} ^ {n_{nnnnnnnnnnnnnnnnnnnnnnnnnn}} ( -1 ) ^ k ( n_{nnnnnnnnnnnnnnnnnnnnnnnnnn} - k + 1 ) n_{nnnnnnnnnnnnnnnnnnnnnnnnnn} ! / k !

$$ a(n)=\sum_{k=0}^n(-1)^k(n-k+1)n!/k! $$

Try it on Desmos!

Next sequence.

\$\endgroup\$
1
\$\begingroup\$

382. Red, 241 bytes, A000179

Red[]

A000179: function [x][
    if x < 3 [return pick [1 -1 0] x + 1]
    x: x - 2
    a: -1
    b: 0
    repeat n x [
        n: n + 2
        c: a
        a: b
        b: (n ** 2 - (2 * n)) * b + (n * c) - (-1 ** n * 4) / (n - 2)
    ]
]

Try it online!

Next sequence!

\$\endgroup\$
3
  • \$\begingroup\$ Didn't you already use language Red for answer #380? \$\endgroup\$ Commented Jun 21, 2022 at 11:51
  • 1
    \$\begingroup\$ @KevinCruijssen The number of times a language is allowed to be used increases by 1 for every 150 answers. So currently, each language can be used thrice, and each will be able to be used an additional time once we reach 450 answers. \$\endgroup\$
    – chunes
    Commented Jun 21, 2022 at 11:54
  • \$\begingroup\$ Ah, you're completely right. It's been quite a while since I posted an answer for this challenge, so forgot about that rule. \$\endgroup\$ Commented Jun 21, 2022 at 11:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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