95
\$\begingroup\$

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.

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\$
  • \$\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

2
\$\begingroup\$

103. VB6, 713 bytes, A000158

Function A000158(ByVal n As Long) As Long
    Dim x1 As Long, x2 As Long, x3 As Long
    A000158 = 0
    n = n + 3

    x1 = 1
    x2 = 1
    x3 = 1
    While x1 ^ (2 / 3) + x2 ^ (2 / 3) + x3 ^ (2 / 3) <= n ' x1
        While x1 ^ (2 / 3) + x2 ^ (2 / 3) + x3 ^ (2 / 3) <= n ' x2
            While x1 ^ (2 / 3) + x2 ^ (2 / 3) + x3 ^ (2 / 3) <= n ' x3
                A000158 = A000158 + 1
                x3 = x3 + 1
            Wend ' x3
            x2 = x2 + 1
            x3 = x2
        Wend ' x2
        x1 = x1 + 1
        x2 = x1
        x3 = x2
    Wend ' x1

    ' no need to return; VB6 will return the value of the variable A000158 (same name as the function)
End Function

Next Sequence

This is a function which takes n as an input and returns a value back to the caller. Used in the manner of answer = A000158(input).

VB6 shares a lot of the syntax with VB.NET, but use completely different compilers (and some different syntaxes).

VB6 longs are actually 32 bit integers.

Unlike C based languages, the / is floating point division. Integer division is handled by \. So 1 / 2 will give 0.5.

The ^ is actually exponent, and not xor like a lot of languages. I believe Xor is the VB6 xor.

VB6 has an implicit variable inside their functions that share the same name. So instead of saying Return <value>, you assign the return value to the function name. In this instance, I set the variable A000158 with my return value. After execution, the value of A000158 is given back to the caller.

Example usage:

I created a new form in the VB6 IDE, dropped two text boxes and a button in it (didn't change the form field names).

Private Sub Command1_Click()
    Text2.Text = A000158(Text1.Text)
End Sub

Function A000158(ByVal n As Long) As Long
    Dim x1 As Long, x2 As Long, x3 As Long
    A000158 = 0
    n = n + 3

    x1 = 1
    x2 = 1
    x3 = 1
    While x1 ^ (2 / 3) + x2 ^ (2 / 3) + x3 ^ (2 / 3) <= n ' x1
        While x1 ^ (2 / 3) + x2 ^ (2 / 3) + x3 ^ (2 / 3) <= n ' x2
            While x1 ^ (2 / 3) + x2 ^ (2 / 3) + x3 ^ (2 / 3) <= n ' x3
                A000158 = A000158 + 1
                x3 = x3 + 1
            Wend ' x3
            x2 = x2 + 1
            x3 = x2
        Wend ' x2
        x1 = x1 + 1
        x2 = x1
        x3 = x2
    Wend ' x1

    ' no need to return; VB6 will return the value of the variable A000158 (same name as the function)
End Function

Type a value into TextBox1, hit the Button1, and watch TextBox2 get populated by the result.

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

105. Windows Batch, 193, A000267

@echo off

:SquareRoot number

set /A number=4 * %1 + 1, last=2, sqrt=number/last
:nextIter
   set /A last=(last+sqrt)/2, sqrt=number/last
if %sqrt% lss %last% goto nextIter
echo %last%

Next sequence

Takes the input number as a command line argument, and prints the result.

Run by saving the above as a .bat file, and execute with windows command prompt (if anyone knows of an online interpreter, I'm happy to update).

Uses an iterative method of computing square roots (Newton's method, I think?). It finds the floor of the square root, which is just what we need for this sequence.

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

106. Objective-C (clang), 45 + 2 = 47 bytes, A000193

int f(int x){ return (int) round(log(x+1)); }

Try it online!

I don't really know Objective-C, but I got something working. Needs the -lm flag (no clue why, but it doesn't work without it).

Does what it says on the tin - rounds the log of the input. Note that it adds 1 to the input to make the sequence 0-indexed.

Next Sequence

\$\endgroup\$
  • 2
    \$\begingroup\$ The -lm flag would be to link against libm, which contains log. I base this explanation entirely on pain I've experienced in the past when figuring out how to compile C programs. \$\endgroup\$ – Peter Taylor Aug 14 '17 at 16:23
  • 2
    \$\begingroup\$ Note for the next sequence (particularly for people who can see comments on the self-deleted attempt): courtesy of jpr2718.org/pell.pdf , when searching for solutions to x^2 - 2y^2 = N it suffices to consider 0 <= 2y^2 <= N, so x^2 <= 2N. This is a consequence of the smallest non-trivial solution to x^2 - 2y^2 = 1 being (3, 2). \$\endgroup\$ – Peter Taylor Aug 14 '17 at 18:45
  • \$\begingroup\$ Why was the attempt deleted? \$\endgroup\$ – NieDzejkob Aug 14 '17 at 19:22
  • \$\begingroup\$ @NieDzejkob Something with int overflow - screencap of comments on deleted answer \$\endgroup\$ – Stephen Aug 14 '17 at 19:25
  • \$\begingroup\$ Uh, is there a language that uses BigInts as it's primary type? I only know Haskell, but it has been used already \$\endgroup\$ – NieDzejkob Aug 14 '17 at 20:24
2
\$\begingroup\$

109. brainfuck, 81 bytes, A000032

,>+>>++>+<<<<[>-<-[>>>>[-<<+<+>>>]<[-<+>]<<[->>+<<]>[->>+<<]<<-]>>>>.<<<]>[+.--]+

Try it online!

Input with raw bytes, or Unicode codepoints, whatever your interpreter supports. Requires large cells for larger inputs. TIO uses Python with an interpreter modified to do input in numbers instead of raw bytes to make testing easier. I probably could golf it down further, but I'm lazy.

Next sequence!

\$\endgroup\$
  • \$\begingroup\$ Is it really BF if you change how input works? :P \$\endgroup\$ – Stephen Aug 15 '17 at 17:41
  • \$\begingroup\$ @StepHen I changed it only for convenience, officially I just used base 256 instead of 10 for I/O. \$\endgroup\$ – NieDzejkob Aug 15 '17 at 17:49
2
\$\begingroup\$

117. Rail, 106 bytes, A001156

$'g'
 -13{f}#
$'f'
 \  /(y)(x){f}(z)(y)s(y)(x)-@
  -*(!z!)(!y!)(!x!)(y)(x)g<
 @-(z)a2(z)a{f}a----#-q0(x)-@

The function named g defined at the top is the function that computed the sequence. f is a helper function that you shouldn't call directly.

Try it online!

Next Sequence (more math! Yay!)

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

119. bc, 139 bytes, A000128

Next Sequence

define f(x) {
	a = 0
	b = 1
	for (i=0; i<x; ++i) {
		aux = b
		b = a + b
		a = aux
	}
	return a
}
n = read()
f(n+5) - (n+1) * (n+2) / 2 - 3

Try it online!

\$\endgroup\$
  • 1
    \$\begingroup\$ If only I had known that such a nice language was still available... \$\endgroup\$ – Christian Sievers Aug 22 '17 at 14:53
2
\$\begingroup\$

120. MATL, 22 bytes, A000139

ttQ:pw2*Q:p*3G*:p2*w/&

Next Sequence

Try it online!

\$\endgroup\$
  • 5
    \$\begingroup\$ How the heck was MATL not taken yet? \$\endgroup\$ – Scott Milner Aug 23 '17 at 21:29
  • \$\begingroup\$ @ScottMilner MATLAB is also free, somehow. \$\endgroup\$ – Business Cat Aug 24 '17 at 17:40
  • 2
    \$\begingroup\$ @BusinessCat As is Maple. In that case, people may just be avoiding the accusation that they copied the code from the OEIS. \$\endgroup\$ – KSmarts Aug 24 '17 at 18:12
  • \$\begingroup\$ @KSmarts I've been tempted several times, though... \$\endgroup\$ – Scott Milner Aug 24 '17 at 18:49
  • \$\begingroup\$ Since PyPy is considered a separate language, C (tcc) and C (clang) are untaken. \$\endgroup\$ – NieDzejkob Aug 26 '17 at 16:48
2
\$\begingroup\$

118. Ly, 128 bytes, A000106

1<n
[>&sy0>lr>l
 [&s>lrysp>l[:lf%:[pp0f10]p![p:0]p1-]p
  <<<0>>[sp>l*sp<<<l+>>]
  <p<*sp<l+>>]
 <<f/<1-]
>&s>lr[sp<l*sp<l+>>]<<u

Next sequence

Try it online!

Easy: just compute values for 1 to n+1 of A000081, then convolve. You may notice that I'm not using Ly's indexing operator I, I'm more thinking in terms of what Haskell calls zipWith. It's a pitty that the division makes Ly use floating point.

The next sequence is a bit simple, I apologize.

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

125. BeanShell, 655 bytes, A000796

import java.math.*;I=new Scanner(System.in).nextInt();D=I+9;O=BigDecimal.ONE;T=O.add(O);N=BigDecimal.TEN;C=new MathContext(2*D,RoundingMode.HALF_DOWN);z(a,b){return a.subtract(b,C).abs(C).compareTo(O.divide(N.pow(D,C)))>-1;}bsqrt(c){x=O;do{x=x.add(x.pow(2,C).add(c.negate(C),C).divide(x.multiply(T,C),C).negate(C),C);}while(z(x.pow(2,C),c));return x;}s=BigDecimal.ZERO;a=O;b=bsqrt(T);for(int i=1;z(a,b);i++){g=a.multiply(b,C);a=a.add(b,C).divide(T,C);b=bsqrt(g);s=s.add(T.pow(i,C).multiply(a.pow(2,C).subtract(g,C),C),C);}print(T.multiply(a.pow(2,C),C).divide(O.subtract(s,C),C).multiply(N.pow(I,C),C).toBigInteger().remainder(BigInteger.TEN).toString());

Try it online!

Next sequence! (easy sequence again)

BeanShell is just an interpreted Java with weak typing, so a high byte count is expected. I probably could golf it more by omitting the MathContext in some BigDecimal calls, but this would have to be tested empirically, which, with the probability of introducing inaccuracies for higher inputs is, in my opinion, not worth the risk. Also prints the input for some reason. This is probably unfixable: input test on TIO.

Square root implementation heavily based on this stackoverflow answer, the pi calculation itself on this Python + mpmath article.

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

126. Scala, 156 bytes, A000655

object Main extends App{
	val a=Console.readInt
	if (a == 0) { print(1) }
	else if (a == 1) { print(3) }
	else if (a == 2) { print(5) }
	else { print(4) }
}

Try it online!

Next Sequence

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

128. Groovy, 82 bytes, A000058

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

The Gs indicate BigIntegers. Simple recursive implementation that counts from a(0) to a(n).

Try it online!

Next Sequence

\$\endgroup\$
  • \$\begingroup\$ D: you monster! My language! +1 \$\endgroup\$ – Magic Octopus Urn Sep 6 '17 at 19:44
  • \$\begingroup\$ a={n,i=0G,x=2G->(i==n)?x:a(n,i+1G,x*x-x+1G)}. I love groovy so much O_O ;_;. I'd KILL for it to be slightly more competitive. \$\endgroup\$ – Magic Octopus Urn Sep 6 '17 at 20:10
  • \$\begingroup\$ @MagicOctopusUrn JS is basically the same, just shorter but without the arbitrary precision, and Python is basically the same, but longer because of lambda and no ?: \$\endgroup\$ – Stephen Sep 6 '17 at 20:26
2
\$\begingroup\$

136. A Pear Tree, 232 bytes, A000029

The program contains unprintable characters, so here is the xxd:

00000000: 7573 6520 4d61 7468 3a3a 4e75 6d53 6571  use Math::NumSeq
00000010: 3a3a 546f 7469 656e 743b 7573 6520 504f  ::Totient;use PO
00000020: 5349 583b 246e 203d 2069 6e74 2824 5f29  SIX;$n = int($_)
00000030: 3b69 6628 246e 297b 2474 203d 204d 6174  ;if($n){$t = Mat
00000040: 683a 3a4e 756d 5365 713a 3a54 6f74 6965  h::NumSeq::Totie
00000050: 6e74 2d3e 6e65 7728 293b 666f 7228 2464  nt->new();for($d
00000060: 203d 2031 3b24 6420 3c3d 2024 6e3b 2464   = 1;$d <= $n;$d
00000070: 2b2b 297b 6966 2821 2824 6e20 2520 2464  ++){if(!($n % $d
00000080: 2929 7b24 7320 2b3d 2024 742d 3e69 7468  )){$s += $t->ith
00000090: 2824 6e2f 2464 292a 322a 2a28 2464 293b  ($n/$d)*2**($d);
000000a0: 7d7d 7072 696e 7420 2473 2f28 322a 246e  }}print $s/(2*$n
000000b0: 292b 2824 6e25 322b 3329 2f34 2a32 2a2a  )+($n%2+3)/4*2**
000000c0: 666c 6f6f 7228 246e 2f32 293b 7d65 6c73  floor($n/2);}els
000000d0: 657b 7072 696e 7420 313b 7d65 7869 7423  e{print 1;}exit#
000000e0: 8025 6b1b 0000 0000                      .%k.....

The bit at the end is just to have a CRC of 0, the rest is standard perl.

No TIO link because it uses the Math::NumSeq::Totient which isn't installed on TIO.

Next sequence!

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

141. MOO, 39 bytes, A000918

return $math_utils:pow(2,args[1])-1-1-0

Next sequence

\$\endgroup\$
  • \$\begingroup\$ Oh lawd, you get 2^n-2 and give the next person THAT? I've been 1 minute late to the easy party like 9 times on this one. I mean not hard... But difficult in Groovy the one language I wanted to use xD. \$\endgroup\$ – Magic Octopus Urn Sep 6 '17 at 19:23
  • \$\begingroup\$ @MagicOctopusUrn Oh come on, it's really not that hard. \$\endgroup\$ – Mr. Xcoder Sep 6 '17 at 19:24
  • 1
    \$\begingroup\$ Invalid. alephalpha answered it the 66th time. \$\endgroup\$ – Mr. Xcoder Sep 6 '17 at 19:25
  • 1
    \$\begingroup\$ A00039 is a(2*n) for a(n)=A000025, implemented in Pyth here \$\endgroup\$ – Giuseppe Sep 6 '17 at 19:42
  • 4
    \$\begingroup\$ I always get MOO and COW confused... \$\endgroup\$ – KSmarts Sep 7 '17 at 2:53
2
\$\begingroup\$

140. MATLAB, 918 bytes, A000052

function q = intToNum(N)
function o = g(N)
n=[0,1,2,3,4,5,6,7,8,9,10+(0:9),(2:9)*10];
e={'zero';'one';'two';'three';'four';'five';'six';'seven';'eight';'nine';'ten';'eleven';'twelve';'thirteen';'fourteen';'fifteen';'sixteen';'seventeen';'eighteen';'nineteen';'twenty';'thirty';'forty';'fifty';'sixty';'seventy';'eighty';'ninety'};
    if N<=20
      o=e{N+1};
    elseif N<100
      if mod(N,10)==0
        s='';
      else
        s=g(mod(N,10));
      end
      o=strcat(e{(N-mod(N,10))==n},s);
    elseif N<1000
      if mod(N,100)==0
        s='';
      else
        s=g(mod(N,100));
      end
      o=strcat(g(floor(N/100)),'hundred',s);
    elseif N>=1000
      o=strcat(g(floor(N/1000)),'thousand',g(mod(N,1000)));
end
end
[~,I]=sort(arrayfun(@g,0:9,'un', 0));
R=0:9;
R=R(I);
S=10:99;
[~,I]=sort(arrayfun(@g,S,'un',0));
R=[R,S(I)];
S=100:999;
[~,I]=sort(arrayfun(@g,S,'un',0));
R=[R,S(I)];
q=R(N);
end

Try it online!

next sequence

To run properly in matlab, this needs to be saved as intToNum.m which is +10 bytes. However, this should also work in Octave with minor modifications (as in the TIO link)

\$\endgroup\$
  • 1
    \$\begingroup\$ I was a moment away from posting an answer in Erlang :( IT'S FUNCTIONAL. DO YOU KNOW HOW FRUSTRATING THAT WAS? +1 anyway \$\endgroup\$ – NieDzejkob Sep 6 '17 at 19:32
  • \$\begingroup\$ @NieDzejkob yeah sorry about that...at least you'll be set for, oh, I don't know, this sequence, if Erlang hasn't been used up by then... \$\endgroup\$ – Giuseppe Sep 6 '17 at 19:39
  • \$\begingroup\$ Does round round or floor? Because if it rounds then it looks like it will give incorrect results. I always generate the sequence up to a 1000 (or as far as you can reasonably go) and I compare it with the txt files from the OEIS. Did you? \$\endgroup\$ – NieDzejkob Sep 6 '17 at 19:45
  • \$\begingroup\$ @NieDzejkob oh good call. I fixed that and a couple things and triple-checked the output. This is definitely correct now (and the spacing allowed me to fudge a bit to keep the byte count the same). \$\endgroup\$ – Giuseppe Sep 6 '17 at 20:10
2
\$\begingroup\$

142. Erlang (escript), 782 bytes, A000039


p(N) -> lists:usort([lists:sort(E)||E<-f(p(N,N))] ++ [[N]]).
p(1,_) -> [[1]];
p(N,M) -> 
    Extra = [ [lists:sort(Y++[X])||Y<-p(N-X,M)] || X<-lists:seq(1,N-1)],
    if N == M -> Extra; true -> [[N]|Extra] end.

f([])  -> [];
f([H|T]=L) when is_integer(H),is_list(T) ->
    case is_flat(T) of
        true  -> [lists:flatten(L)];
        false -> f([e(H,E) || E <- T]) 
    end;
f([H|T]) -> f(H) ++ f(T);
f(H)    -> [H].

e(A,B) when is_list(B) -> [A|B];
e(_,B) -> B.

is_flat(L) when is_list(L) -> length([E||E<-L, is_list(E)]) < 2;
is_flat(_) -> true.

rank(P) -> lists:max(P) - length(P).

score(P) -> (1 - abs(rank(P) rem 2)) * 2 - 1.

a(0) -> 1;
a(N) -> lists:sum(lists:map(fun(P) -> score(P) end, p(N))).

main([])-> {ok, [N]} = io:fread("", "~d"),
io:fwrite("~p", [a(2*N)]).

Try it online!

Next sequence!

Partition function from here.

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

145. Phoenix, 271 bytes, A000068

#https://stackoverflow.com/a/39743570/7605753
function is_prime(n){for(var $i=n>>1;$i&&n%$i--;);return!$i&&n>1;}
$n = readline();
$j = 0;
$k = 1;
while (1) {
 $m = pow($k, 4) + 1;
 if (is_prime($m)) {
  if ($j == $n) {
   echo $k;
   exit();
  }
  $j += 1;
 }
 $k += 1;
}

Try it online!

Next Sequence

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

146. PicoLisp, 121 bytes, A000271

(de a (n) (cond ((= n 0) 1) ((< n 3) 0) ((< n 4) 1) (T (+ (* (- n 1) (a (- n 2))) (* (- n 1) (a (- n 1))) (a (- n 3))))))

Next Sequence

Try it online!

I also implemented A000179 in PicoLisp to try and do sums on it, but this was faster.

I'm running out of Lisp variants to work on!

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

161. Ruby, 208 bytes, A000315

size = gets.chomp.to_i
puts (1..size).to_a.permutation.to_a.permutation(size).to_a.select{|x| x.transpose.all? {|y| y.uniq.size == y.size} and x[0].sort == x[0] and x.transpose[0].sort == x.transpose[0]}.size

Note that this is an extremely slow implementation. I might make a faster one eventually and post it as a side note (so as to not change the bytecount)

Also, this is my first Ruby program :D

Try it on Repl.it!

Next Sequence

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

162. Julia 0.6, 448 bytes, A000208

This is the third time that I've implemented A000013 in this challenge.

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 A000208(n)
  x = 0
  if n <= 1
    x = 1
  elseif n/2 == n÷2
    x = (A000013(2*n) + A000013(n)) / 2
  else
    x = A000013(2*n) / 2
  end
  return Int(x)
end  

Try it online!

Next Sequence

\$\endgroup\$
  • \$\begingroup\$ doesn't Julia have a mod operator? It's probably %, but I get that using ÷ is fun, too! \$\endgroup\$ – Giuseppe Sep 19 '17 at 15:41
2
\$\begingroup\$

164. cQuents, 1000 bytes, A000227

$0:R_e^$)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Try it online!

Next Sequence

Explanation

$0           0-indexed
  :          Mode: Sequence - output whole sequence, or nth item for input n
   R    )    Round - closing paren added if absent
    _e^$     e to the power of the current index
             Spaces for padding
\$\endgroup\$
  • \$\begingroup\$ I really like the next sequence! \$\endgroup\$ – Giuseppe Sep 19 '17 at 17:30
  • 2
    \$\begingroup\$ Am I doing something wrong or is the formula for the next sequence completely incorrect? \$\endgroup\$ – NieDzejkob Sep 19 '17 at 17:43
  • 2
    \$\begingroup\$ @NieDzejkob I'm getting completely wrong answers too, so I'm guessing there's a mistake in the formula. \$\endgroup\$ – KSmarts Sep 19 '17 at 17:52
  • \$\begingroup\$ somebody had better tell David Wilson... \$\endgroup\$ – Giuseppe Sep 19 '17 at 18:04
  • \$\begingroup\$ @Giuseppe is there a way to contact users of the OEIS? \$\endgroup\$ – NieDzejkob Sep 19 '17 at 18:18
2
\$\begingroup\$

165. Forth, 114 bytes, A001000

: C 4 * 5 - s>f fsqrt f>s ;
: A 1+ dup 2 < IF 1+ ELSE dup dup * swap dup C dup dup * 4 / 1+ -rot * -1 * + + THEN ;

Try it online

Next Sequence

This could have been golfed to 106 by moving C into the function A, but that OEIS sequence looked harder for the next person. Or it grew faster, anyway.

Explanation:

In the previous answer, people were unsure of the algorithm for this one. It looked difficult, but the OEIS page stated: "This is the same sequence (apart from the initial term) as A071111." So, I used that sequence, then used an IF THEN ELSE to output 2 if the input is 1.

I added one at the beginning of the function because the sequence has an offset of one. This makes it zero-indexed.

The algorithm:

a(n) = n^2 - n*c(n) + floor(c(n)^2/4) + 1, where c(n) = floor(sqrt(4n-5))

The comments on the page for A071111 also state the results for a(100) and a(1000), and mine are the same.

\$\endgroup\$
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\$
  • 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\$ – totallyhuman Sep 21 '17 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 '17 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\$ – HyperNeutrino Sep 21 '17 at 21:17
  • \$\begingroup\$ @HyperNeutrino why wasn't that answer just fixed? \$\endgroup\$ – NieDzejkob Sep 22 '17 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\$

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\$
  • \$\begingroup\$ Oh c'mon, not this "sequence sans formula" stuff again... \$\endgroup\$ – totallyhuman Sep 26 '17 at 16:21
  • \$\begingroup\$ @icrieverytim read der papers \$\endgroup\$ – Stephen Sep 26 '17 at 16:24
  • \$\begingroup\$ a) There's so many papers and b) I don't understand half the stuff they have there. :P \$\endgroup\$ – totallyhuman Sep 26 '17 at 16:25
  • \$\begingroup\$ Nooo, I was writing a solution in Shakespeare... whatever. \$\endgroup\$ – NieDzejkob Sep 26 '17 at 16:31
  • 1
    \$\begingroup\$ rosettacode.org/wiki/Free_polyominoes_enumeration Pick a language, any language, no need for cri \$\endgroup\$ – Husnain Raza Sep 27 '17 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\$
  • 2
    \$\begingroup\$ dagnabbit, I had a Cubix solution all ready, I just needed one pad byte to get to 53 :( \$\endgroup\$ – Giuseppe Oct 2 '17 at 23:12
2
\$\begingroup\$

205. Commata, 109 bytes, A000053

Due to the fact that the proper name breaks the snippet, it has been changed. The proper name is ,,,

14 18 23 28 34 42 50 59 66 72 79 86 96 103 110 116 125 137 145 157 168 181 191 207 215 225 231 238 242 ↺•

Try it online!

Next sequence. (wtf)

Hello darkness,,, my old friend.

\$\endgroup\$
  • 1
    \$\begingroup\$ How can you test if a graph is planar given an adjacency matrix of said graph? \$\endgroup\$ – Husnain Raza Oct 4 '17 at 23:00
  • 1
    \$\begingroup\$ @HusnainRaza You can implement an algorithm on your own, or you can just use Mathematica. (PlanarGraphQ) \$\endgroup\$ – KSmarts Oct 5 '17 at 19:24
  • 1
    \$\begingroup\$ @HusnainRaza SageMath, Magma, etc. have already been used, and I think this is a reasonable sequence to use math software on. Maple has a graph theory package with an IsPlanar test, if you'd prefer. \$\endgroup\$ – KSmarts Oct 6 '17 at 13:37
  • 1
    \$\begingroup\$ sorry, way too hard and dont have enough time, can someone take over? \$\endgroup\$ – Husnain Raza Oct 8 '17 at 2:13
  • 1
    \$\begingroup\$ f[x_] := Length[GraphData["Triangulated", x]] works up to x=9... \$\endgroup\$ – Stephen Oct 9 '17 at 13:23

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.