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
    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
    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\$ 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
    Dec 22, 2017 at 12:44
  • 6
    \$\begingroup\$ Chat room \$\endgroup\$
    – DELETE_ME
    Dec 22, 2017 at 12:45

407 Answers 407

1
7 8
9
10 11
14
2
\$\begingroup\$

169. Chez Scheme, 84 bytes, A000261

(define (a n)
(if (< n 1)
 n 
 (+ (* (+ n 1) (a (- n 1))) (* (- n 2) (a (- n 2))))))

Try it online!

Next sequence

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Note that you could hardcode the next sequence since there are 1000 terms. However, might want to wait until everybody gives up... \$\endgroup\$ Sep 21, 2017 at 16:51
  • \$\begingroup\$ @icrieverytim I don't think anybody will give up, the next sequence, while it looks intimidating, is relatively straightforward. \$\endgroup\$
    – Giuseppe
    Sep 21, 2017 at 17:18
  • \$\begingroup\$ I tried the next sequence once and it was not particularly easy. I never got around to finishing because a 3-chain of answers got deleted because of an integer precision issue with a Java-based language. \$\endgroup\$
    – hyper-neutrino
    Sep 21, 2017 at 21:17
  • \$\begingroup\$ @HyperNeutrino why wasn't that answer just fixed? \$\endgroup\$
    – Maya
    Sep 22, 2017 at 4:45
2
\$\begingroup\$

170. Python 3 (PyPy), 204 bytes, A000084

n=int(input())+1
a=[0,1,1,2]
p=[0,1,3,7]
for m in range(4,n+1):s=sum([d*a[d]for d in range(1,m)if m%d==0]);u=p[m-1]+2*sum([p[k]*a[m-k]for k in range(1,m-1)])+s;a+=[u//m];p+=[s+u]
print(2*a[n]if n>1else 1)

Try it online!

Next sequence!

4 Pythons down, 2 to go. Wait, there's Python 0 but no one used it in the first 150 answers. 3 to go.

Ported the second Maple program for A000669. Next sequence is Lucas numbers - as easy as Fibonacci, but nicer.

\$\endgroup\$
2
\$\begingroup\$

172. Python 1, 55 bytes, A000541

S=0
for s in range(-~input()):S=S+s*s*s*s*s*s*s
print S

Try it online!

Next Sequence: A000055

\$\endgroup\$
2
\$\begingroup\$

173. Python 2 (IronPython), 257 bytes, A000055

c={0:0,1:1}
def b(n):
 if n not in c:c[n]=sum([sum([d*b(d)for d in range(1,j+1)if j%d==0])*b(n-j)for j in range(1,n)])//(n-1)
 return c[n]
def a(n):return 1if n==0 else b(n)-(sum([b(k)*b(n-k)for k in range(n)])-(b(n//2)if n%2==0 else 0))//2
print a(input())

Try it online!

Next sequence!

2 versions of Python on the wall, 2 versions of Python. Take one down and pass it around, 1 version of Python on the wall.

Caches the results of b because it seemed like it would take forever to compute for big n without it. Didn't test whether it does anything useful, but it probably does.

\$\endgroup\$
2
\$\begingroup\$

176. JavaScript (ES6), 184 bytes, A000122

function A000122(n) {
 if (n === 0) { return 1; }
 squares = [];
 for (i = 0; i <= 32; i++) {
  squares.push(i*i);
 }
 if (~squares.indexOf(n)) {
  return 2;
 } else {
  return 0;
 }
}

Try it online!

Next Sequence

\$\endgroup\$
2
\$\begingroup\$

188. Groovy, 105 bytes, A000321

def a
a = { n -> 
	if (n == 0G) { 1 }
	else if (n == 1G) { -1 }
	else {
		-a(n-1G)-2G*(n-1G)*a(n-2G)
	}
}

Try it online!

Next Sequence

\$\endgroup\$
6
  • \$\begingroup\$ Oh c'mon, not this "sequence sans formula" stuff again... \$\endgroup\$ Sep 26, 2017 at 16:21
  • \$\begingroup\$ @icrieverytim read der papers \$\endgroup\$
    – Stephen
    Sep 26, 2017 at 16:24
  • \$\begingroup\$ a) There's so many papers and b) I don't understand half the stuff they have there. :P \$\endgroup\$ Sep 26, 2017 at 16:25
  • \$\begingroup\$ Nooo, I was writing a solution in Shakespeare... whatever. \$\endgroup\$
    – Maya
    Sep 26, 2017 at 16:31
  • 1
    \$\begingroup\$ rosettacode.org/wiki/Free_polyominoes_enumeration Pick a language, any language, no need for cri \$\endgroup\$ Sep 27, 2017 at 2:33
2
\$\begingroup\$

189. C# (Visual C# Compiler), 1182 bytes, A000105

Three parts - the function (824 bytes) + comparer class used in function (273 bytes) + imports (85 bytes)

n=>{var t=new Func<P,P>[]{p=>new P(p.Y,-p.X),p=>new P(-p.X,-p.Y),p=>new P(-p.Y,p.X),p=>new P(-p.X,p.Y),p=>new P(-p.Y,-p.X),p=>new P(p.X,-p.Y),p=>new P(p.Y,p.X)};Func<P[],P[][]>r=l=>new[]{l}.Concat(new int[7].Select((x,i)=>l.Select(p=>t[i](p)).ToArray())).ToArray();Func<int,P[][]>k=null;k=a=>a<2?new[]{new[]{new P(0,0)}}:k(a-1).SelectMany(l=>l.SelectMany(p=>new[]{new P(p.X-1,p.Y),new P(p.X+1,p.Y),new P(p.X,p.Y-1),new P(p.X,p.Y+1)}).Where(p=>!l.Contains(p)).Distinct().Select(p=>r(l.Concat(new[]{p}).ToArray()).Select(o=>o.Select(c=>new P(c.X-o.Select(q=>q.X).Min(),c.Y-o.Select(q=>q.Y).Min())).OrderBy(q=>q.X).ThenBy(q=>q.Y).ToArray()).Aggregate((m,o)=>(m==null||string.Concat(o.Select(x=>$"({x.X},{x.Y})")).CompareTo(string.Concat(m.Select(x=>$"({x.X},{x.Y})")))<0?o:m)))).Distinct(new C()).ToArray();return k(n).Length;}

class C:IEqualityComparer<P[]>{public bool Equals(P[] f,P[] s)=>f==s?1>0:(f==null|s==null)?1<0:f.OrderBy(p=>p.X).ThenBy(p=>p.Y).Zip(s.OrderBy(p=>p.X).ThenBy(p=>p.Y),(a,b)=>a==b).All(x=>x);public int GetHashCode(P[]l)=>l.Aggregate(0,(a,b)=>a.GetHashCode()^b.GetHashCode());}

using System.Collections.Generic;using P=System.Windows.Point;namespace System.Linq{}

Try it online!

Next sequence

I accidentaly deleted the extended version after I golfed it.... Also the code has 2 unneeded spaces added because A001180 was not fun.

\$\endgroup\$
2
\$\begingroup\$

193. Hodor, 160 bytes, A000326

HODOR! = HoDoRHoDoR( HODOR? ) {
	HOdor!!!(HODOR? == 0)
	HODOR:: 0;
	HODOR = 1;
	Hodor! = 2;
	hodor = 3;
	HODOR:: HODOR? * (hodor * HODOR? - HODOR ) / Hodor! ;
}

Try it online!
Next sequence

It's a little inefficient, but please don't hold it against Hodor. He is a little slow, but he's a beautiful gentle giant.

\$\endgroup\$
2
\$\begingroup\$

202. Oasis, 50 bytes, A000213

bc+d+$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$111

$s are filler.

Try it online!

Next Sequence

\$\endgroup\$
1
  • 2
    \$\begingroup\$ dagnabbit, I had a Cubix solution all ready, I just needed one pad byte to get to 53 :( \$\endgroup\$
    – Giuseppe
    Oct 2, 2017 at 23:12
2
\$\begingroup\$

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

\$\endgroup\$
3
  • \$\begingroup\$ Ugh. I was about to test this. I think this is the theme of this challenge. \$\endgroup\$
    – Maya
    Oct 10, 2017 at 12:48
  • \$\begingroup\$ @NieDzejkob yea, was hit the same way a few times. they should have set some way to reserve spots \$\endgroup\$
    – Uriel
    Oct 10, 2017 at 12:49
  • \$\begingroup\$ Yeah, I've seen some other [answer-chaining] question do that. \$\endgroup\$
    – Maya
    Oct 10, 2017 at 12:53
2
\$\begingroup\$

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!

\$\endgroup\$
2
  • \$\begingroup\$ Wait, I thought it was one of these selfreferential sequences like "OEIS sequences that contain their own index number" \$\endgroup\$
    – Maya
    Oct 10, 2017 at 13:57
  • \$\begingroup\$ lol no meta sequences pls \$\endgroup\$ Oct 10, 2017 at 13:58
2
\$\begingroup\$

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!

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

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.

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

219. Maxima, 127 bytes, A000702

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.

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Maple and Mathematica for the next sequence seem to be using a formula not mentioned in the formula section. \$\endgroup\$
    – Maya
    Oct 11, 2017 at 14:52
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – KSmarts
    Oct 11, 2017 at 15:00
  • \$\begingroup\$ @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... \$\endgroup\$ Oct 11, 2017 at 17:38
2
\$\begingroup\$

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?

\$\endgroup\$
5
  • 1
    \$\begingroup\$ I know how to code the next sequence, but idk what language to do it in :( \$\endgroup\$ Oct 23, 2017 at 12:08
  • \$\begingroup\$ @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. \$\endgroup\$
    – Maya
    Oct 23, 2017 at 12:31
  • \$\begingroup\$ @HusnainRaza I have discovered a truly marvelous demonstration of this proposition that this margin is too narrow to contain. \$\endgroup\$
    – KSmarts
    Oct 23, 2017 at 14:14
  • \$\begingroup\$ @NieDzejkob But the equivalence checking is the hard part, isn't it? \$\endgroup\$
    – KSmarts
    Oct 23, 2017 at 14:17
  • \$\begingroup\$ @KSmarts yes, but the point is an easy to use language with the boilerplate serving at least as a good syntax example. \$\endgroup\$
    – Maya
    Oct 23, 2017 at 14:37
2
\$\begingroup\$

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.

\$\endgroup\$
4
  • 2
    \$\begingroup\$ Mathematics is never nonsense. \$\endgroup\$
    – DELETE_ME
    Oct 27, 2017 at 15:10
  • \$\begingroup\$ @user202729 That code looks like nonsense to me :P \$\endgroup\$ Oct 27, 2017 at 15:10
  • \$\begingroup\$ @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. \$\endgroup\$
    – KSmarts
    Oct 27, 2017 at 15:32
  • 3
    \$\begingroup\$ @user202729 Actually... \$\endgroup\$
    – KSmarts
    Oct 27, 2017 at 16:33
2
\$\begingroup\$

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

\$\endgroup\$
5
  • 1
    \$\begingroup\$ 2*>U2XmX¹>c- crying +1 though lol, despite making mine no longer matter. \$\endgroup\$ Oct 27, 2017 at 19:18
  • \$\begingroup\$ Nice bytecount! \$\endgroup\$
    – Maya
    Oct 27, 2017 at 19:19
  • 2
    \$\begingroup\$ I hope I will finish my Trefunge program before someone else finds an easier language for this sequence... \$\endgroup\$
    – Maya
    Oct 27, 2017 at 20:39
  • 1
    \$\begingroup\$ @NieDzejkob I found a bunch of easier languages. Go to tio.run, deselect "recreational," and you'll get a whole list of them! \$\endgroup\$
    – KSmarts
    Oct 27, 2017 at 23:08
  • 1
    \$\begingroup\$ @KSmarts actually, this doesn't work. Haskell still shows up on the list. \$\endgroup\$
    – Maya
    Oct 28, 2017 at 11:12
2
\$\begingroup\$

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.

\$\endgroup\$
8
  • \$\begingroup\$ It segfaults for n=7? oookay. \$\endgroup\$
    – Giuseppe
    Sep 12, 2017 at 0:10
  • \$\begingroup\$ ... which makes this answer invalid. \$\endgroup\$ Sep 12, 2017 at 1:26
  • \$\begingroup\$ @ppperry "fixed" \$\endgroup\$
    – Maya
    Sep 12, 2017 at 5:36
  • 7
    \$\begingroup\$ This isn't at all self-explanatory. \$\endgroup\$ Sep 12, 2017 at 10:31
  • 2
    \$\begingroup\$ @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~~. \$\endgroup\$
    – Maya
    Sep 12, 2017 at 12:44
2
\$\begingroup\$

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!

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Eleventh? I don't see deleted posts (except my own) and I'm on the 9th... \$\endgroup\$
    – Maya
    Nov 7, 2017 at 19:02
  • \$\begingroup\$ @NieDzejkob yeah, the eleventh page if you include all deleted posts. \$\endgroup\$
    – Giuseppe
    Nov 7, 2017 at 19:37
  • \$\begingroup\$ "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. \$\endgroup\$
    – DELETE_ME
    Nov 8, 2017 at 11:07
  • \$\begingroup\$ Yay! No formula! \$\endgroup\$
    – DELETE_ME
    Nov 8, 2017 at 11:08
  • \$\begingroup\$ @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. \$\endgroup\$
    – KSmarts
    Nov 8, 2017 at 14:28
2
\$\begingroup\$

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.

\$\endgroup\$
10
  • \$\begingroup\$ Isn't next-seq a PPCG challenge lol \$\endgroup\$
    – hyper-neutrino
    Sep 18, 2017 at 23:54
  • 1
    \$\begingroup\$ 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). \$\endgroup\$ Sep 19, 2017 at 6:56
  • \$\begingroup\$ And this code doesn't calculate it correctly. Input 10 should give 197 and gives 137. \$\endgroup\$ Sep 19, 2017 at 7:00
  • \$\begingroup\$ 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? \$\endgroup\$
    – Maya
    Sep 19, 2017 at 8:45
  • 1
    \$\begingroup\$ There's also the problem of segfaulting for n > 100 - keep only the last 3 numbers or allocate this array dynamically \$\endgroup\$
    – Maya
    Sep 19, 2017 at 9:38
2
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
4
  • \$\begingroup\$ Ugh, the next sequence is gross. \$\endgroup\$ Nov 20, 2017 at 21:25
  • \$\begingroup\$ What if the conjecture is false? Don't you need to prove it? \$\endgroup\$
    – DELETE_ME
    Nov 21, 2017 at 9:55
  • \$\begingroup\$ 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. \$\endgroup\$
    – Maya
    Nov 21, 2017 at 10:39
  • \$\begingroup\$ @user202729 alternatively, he can verify the results for n up to a thousand. \$\endgroup\$
    – Maya
    Nov 21, 2017 at 10:41
2
\$\begingroup\$

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.

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

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)
\$\endgroup\$
2
  • \$\begingroup\$ Sorry @NieDzejkob :( but you couldn't have answered anyway, your hour wasn't up! \$\endgroup\$
    – Giuseppe
    Oct 10, 2017 at 14:41
  • \$\begingroup\$ 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. \$\endgroup\$
    – Maya
    Oct 10, 2017 at 14:44
2
\$\begingroup\$

264. PowerShell, 102 bytes, A000493

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

# Please, let's get this to 102. Please?

Try it online!

Next sequence.

\$\endgroup\$
6
  • \$\begingroup\$ We've already had 64 \$\endgroup\$ Nov 24, 2017 at 17:20
  • \$\begingroup\$ ...I looked at the last answer and it said 64. >.> Padding, hang on. \$\endgroup\$ Nov 24, 2017 at 17:21
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – Colera Su
    Nov 24, 2017 at 23:46
  • 2
    \$\begingroup\$ @totallyhuman well, we got the shit together :P \$\endgroup\$ Nov 25, 2017 at 0:12
  • 1
    \$\begingroup\$ I just noticed that the bytecount of this answer is a palindrome of the bytecount of the other PowerShell answer :) \$\endgroup\$
    – Maya
    Jan 3, 2018 at 14:55
2
\$\begingroup\$

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

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

135. Husk, 29 bytes, A000277

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

Try it online!

Next Sequence.

\$\endgroup\$
2
\$\begingroup\$

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

\$\endgroup\$
1
  • \$\begingroup\$ +100 rep if someone does the next one in Beatnik \$\endgroup\$
    – Maya
    Sep 7, 2017 at 16:22
2
\$\begingroup\$

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

\$\endgroup\$
2
  • \$\begingroup\$ I was working on 6502 asm for 272 when this was posted \$\endgroup\$
    – Tornado547
    Dec 7, 2017 at 20:22
  • \$\begingroup\$ @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! \$\endgroup\$
    – Giuseppe
    Dec 7, 2017 at 20:38
1
7 8
9
10 11
14

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.