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

129. ExtraC, 482 bytes, A000082

import math

int isprime(long n)do
	if(n equals 1) return 0
	if(n equals 2) return 1
	if(not(n modulus 2)) return 0
	long max be sqrt(n)
	for(long i be 2 AND i less max AND increment i)do
		if(not(n modulus (2 times i plus 1))) return 0
	end
	return 1
end

long n be readint plus 1
double r be 1
for(long p be 1 AND p minus 1 less n AND increment p)do
	if(not(n modulus p))do
		if(isprime(p))do
			r be r times (F(1) divide p plus 1)
		end
	end
end
print((int)(r times (n times n)))

Try it online!

Next sequence!

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

131. Bean, 116 bytes, A000090

00000000: a64d a048 8040 a06a 52a0 6acc a06a 8d53  ¦M H.@ jR jÌ j.S
00000010: a048 4ca0 6a8c 253a 253a a64d a062 8050   HL j.%:%:¦M b.P
00000020: 80a0 1f20 803c a64d a05e 8053 a062 4ca0  . . .<¦M ^.S bL 
00000030: 438e 253c a64d a05f 804c d3a0 4820 5e8d  C.%<¦M _.LÓ H ^.
00000040: 53d0 80a0 1f20 8046 a53c 205e 264c ccd3  SÐ. . .F¥< ^&LÌÓ
00000050: a048 2043 8d53 a062 4ccc a05f 8e53 d080   H C.S bLÌ _.SÐ.
00000060: a01f 2080 3b4c a53a 8e25 3c8b 2581 008e   . .;L¥:.%<.%...
00000070: 205f ae35                                 _®5

Try it online!

Next sequence!

\$\endgroup\$
1
  • \$\begingroup\$ If I read the haskell for the next sequence right, A000116(n) = A000013(2*n), which is confirmed in comments of A00013. \$\endgroup\$
    – Maya
    Sep 3, 2017 at 8:50
1
\$\begingroup\$

133. CHICKEN Scheme, 643 bytes, A000903

(define (g x) 
(cond ((= x 0) 1) (else x)))
(define (div4 x)
(/ (- x (remainder x 4)) 4))
(define (factorial x)
(cond ((< x 3) (g x)) 
(else (* x (factorial (- x 1))))))
(define (a37223 x)
(define y (/ (- x (remainder x 2)) 2))
(* (factorial y) (expt 2 y)))
(define (a37224 x) 
(define y (div4 x))
(cond ((> (remainder x 4) 1) 0) ((= x 1) 1) (else (/ (* 2 (factorial (- (* 2 y) 1))) (factorial (- y 1))))))
(define (a85 x)
(cond ((< x 2) 1) (else (+ (a85 (- x 1)) (* (- x 1) (a85 (- x 2)))))))
(define (a00000000000000000000000000000000000000903 x)
(cond ((= x 1) 1) (else (/ (+ (factorial x) (+ (a37223 x) (* 2 (+ (a37224 x) (a85 x))))) 8))))

Try it online!

Next Sequence

\$\endgroup\$
1
  • \$\begingroup\$ It's 627 bytes, not 526, and the Next Sequence link does not point to any of these sequences. I just finished writing a program for A000643... \$\endgroup\$
    – Maya
    Sep 4, 2017 at 8:17
1
\$\begingroup\$

138. Chapel, 689 bytes, A000701

proc sigma(n: int): int { // A000203
	var sum: int = 0;
	for d in 1..n {
		if n % d == 0 {
			sum += d;
		}
	}

	return sum;
}

proc sumodd(n: int): int { // A000593
	var sum: int = 0;
	for d in 1..n {
		if (n % d == 0) & (d % 2 == 1) {
			sum += d;
		}
	}

	return sum;
}

proc part(n: int): int { // A000041
	if n == 0 { return 1; }

	var sum: int = 0;
	for k in 0..(n-1) {
		sum += sigma(n-k) * part(k);
	}

	return sum / n;
}

proc helper(n: int): int { // A000700
	if n == 0 { return 1; }

	var sum: int = 0;
	for k in 1..n {
		sum += (if k % 2 == 0 then -1 else 1) * sumodd(k) * helper(n-k);
	}

	return sum / n;
}

var n: int;
n = stdin.read(int);

write((part(n) - helper(n)) / 2);

Should be pretty self-explanatory. I'm surprised such a nice language was available for so long.

Try it online!

Next sequence!

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

139. Perl 6, 52 bytes, A000689

my $n=get();
$n= 2**$n;
print substr($n,$n.chars-1);

Try it online!

Next Sequence

\$\endgroup\$
3
  • \$\begingroup\$ The next sequence would be a lot easier if it weren't for the teens. \$\endgroup\$
    – KSmarts
    Sep 6, 2017 at 16:38
  • \$\begingroup\$ @KSmarts well, there is a Mathematica program, and Mathematica 11 hasn't been used yet... \$\endgroup\$
    – Stephen
    Sep 6, 2017 at 16:59
  • 1
    \$\begingroup\$ If you'll give me $300, I'll do it in Mathematica. Or give me $240, and I'll do it in Maple. \$\endgroup\$
    – KSmarts
    Sep 6, 2017 at 18:43
1
\$\begingroup\$

151. Python 2, 31 bytes, A000125

lambda n:(n**3 + 5 * n + 6) / 6

Try it online!

Next sequence.

Alright, so the next one looks like an absolute doozy when you look at the title:

Number of n-bead necklaces with 2 colors when turning over is not allowed; also number of output sequences from a simple n-stage cycling shift register; also number of binary irreducible polynomials whose degree divides n.

Yeah... I dunno how people comprehend this stuff... But the formula doesn't look too bad.

a(n) = (1/n)*Sum_{ d divides n } phi(d)*2^(n/d), where phi is A000010.

Here's a Python 3 implementation:

import math

phi = lambda n: len([i for i in range(1, n + 1) if math.gcd(n, i) == 1])
A000031 = lambda n: n and sum(phi(d) * 2 ** (n / d) for d in range(1, n + 1) if n % d == 0) / n or 1

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ Unfortunately, 29 bytes is unavailable. 31 is the lowest available score \$\endgroup\$ Sep 11, 2017 at 15:07
  • \$\begingroup\$ Sike, you thought. :P And yes, I do love my Python 2 for golfing. \$\endgroup\$ Sep 11, 2017 at 15:07
1
\$\begingroup\$

152. Mathics, 136 bytes, A000031

EulerPhi[x_] := Sum[If[CoprimeQ[i,x], 1, 0], {i, 1, x}]
OEIS[x_] := Sum[If[IntegerQ[x/d], (EulerPhi[d]*2^(x/d)), 0], {d,1,x}]/x
OEIS[#]&

Next Sequence.

Try it online!

This is just my previous Mathics answer, modified for the new sequence.

\$\endgroup\$
6
  • \$\begingroup\$ Next one is quite the doozy - only 45 terms known, apparently \$\endgroup\$
    – Stephen
    Sep 11, 2017 at 17:14
  • \$\begingroup\$ @Stephen I only looked at the title before posting this. I guess it's one of those deceptively simple problems. \$\endgroup\$
    – KSmarts
    Sep 11, 2017 at 17:31
  • \$\begingroup\$ Those usually have a formula or at least a Mathematica program though :P \$\endgroup\$
    – Stephen
    Sep 11, 2017 at 17:33
  • \$\begingroup\$ What have you done \$\endgroup\$
    – Maya
    Sep 11, 2017 at 17:50
  • \$\begingroup\$ I believe one of the linked papers has a formula for the next one, except it's a sum over certain orders of the integers, which is quite nasty (page 13 of the doc, page 147 of the journal). At least we have almost every language available again; we won't have to do INTERCAL again for another hundred answers or so. \$\endgroup\$
    – Giuseppe
    Sep 11, 2017 at 17:54
1
\$\begingroup\$

155. Python 3, 83 bytes, A000262

a = lambda n: (2 * n - 1) * a(n - 1) - (n - 1) * (n - 2) * a(n - 2) if n > 1 else 1

Try it online!

Next sequence.

I shall starve this challenge of Python for the future. Fight me. ಠ_ಠ

...Also good luck with the next sequence. :P

\$\endgroup\$
2
  • \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$
    – Dennis
    Sep 24, 2017 at 16:25
  • \$\begingroup\$ ...but now I can't comment on my own post. ಠ_ಠ \$\endgroup\$ Sep 24, 2017 at 16:34
1
\$\begingroup\$

158. Jelly, 48 bytes, A000376

ḣ1‘Ṭœṗ
ÇḢU$;$F
ÇÐĿ
ṫ0ḢṢ⁼$
‘RŒ!Q3Ŀ€ÇÐfL€Ṁ’¹¹¹¹¹¹¹

Try it online!

Explanation

ḣ1‘Ṭœṗ                  Helper Link 1; splits the list into two sublists, the first of which is reversed
ḣ1                      First 1 element(s) without modifying the original list
  ‘                     Increment
   Ṭ                    Generate a boolean list with 1s at the indices in (left)
    œṗ                  Partition, keeping borders
ÇḢU$;$F                 Helper Link 2; applies 1 iteration of the TopSwop operation
Ç                       Partition with length of the first element
 ḢU$;$                  Reverse the first list and concatenate it with the second list
 ḢU$                    Reverse the first list
 Ḣ                      Head; modifies the list
  U                     Reversed
    ;                   Concatenated with (the second list, implicit)
      F                 Flatten
ÇÐĿ                     Helper Link 3; completes TopSwops for a list
 ÐĿ                     While the results are unique (collects intermediate results)
Ç                       TopSwop once
ṫ0ḢṢ⁼$                  Helper Link 4; returns whether or not a list is sorted
ṫ0                      Last 0 sublists (gives the last one without modifying the original list)
  Ḣ                     Head; this unwraps the length 1 list of a single list
   Ṣ⁼$                  Is it sorted?
   Ṣ                    The list sorted
    ⁼                   equals (the original list, implicit) (non-vectorizing)
‘RŒ!Q3Ŀ€ÇÐfL€Ṁ’¹¹¹¹¹¹¹  Main Link
‘                       Increment (for 0-indexing)
 R                      Range
  Œ!                    All permutations (with duplicates)
    Q                   Deduplicate (technically unnecessary)
       €                For each sublist
     3Ŀ                 Apply Helper Link 3; completes TopSwops
         Ðf             Keep sublists where
        Ç               The end result is sorted
            €           For each element
           L            Yield its length
             Ṁ          Get maximum length
              ’         Decrement because the first "iteration" is the beginning list
               ¹¹¹¹¹¹¹  Identity function chained 7 times; has no effect in this situation

Next Sequence - More necklaces yay

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

159. Java (OpenJDK 8), 778 bytes, A000048

import java.util.Scanner;
import java.math.BigInteger;

public class Main {
 static boolean isPrime(int n){
  if(n % 2 == 0) return n == 2;
  for(int d = 3;d*d <= n;d += 2){
   if(n % d == 0) return false;
  }

  return true;
 }

 static int mu(int n){
  int r = 1;
  for(int p = 2;p <= n;p++){
   if(!isPrime(p) || n % p != 0) continue;
   if(n % (p*p) == 0) return 0;
   r = -r;
  }

  return r;
 }

 static BigInteger a(int n){
  if(n == 0) return BigInteger.ONE;
  BigInteger s = BigInteger.ZERO;
  for(int d = 1;d <= n;d += 2){
   if(n % d == 0) s = s.add(BigInteger.valueOf(mu(d)).shiftLeft(n / d));
  }

  return s.divide(BigInteger.valueOf(2 * n));
 }

 public static void main(String args[]){
  int n = new Scanner(System.in).nextInt();
  System.out.println(a(n));
 }
}

Try it online!

Next sequence!

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

163. R, 227 bytes, A000448

A000448 <- function(n){
  if(n == 0)
    return(0)
  k <- 1
  l <- (0:k)^2
  g <- table(combn(l,2,sum))
  while(max(g) < n+1){
    k <- k+1
    l <- c(l,k^2)
    g <- table(combn(l,2,sum))
  }
  min(as.numeric(names(g[g>n])))
}

Try it online!

Next Sequence

Brute force approach! Takes sums of unordered pairs of squares, combn(l,2,sum), tabulates them with table to get counts, and then iterates until it finds one that can be written as the sum of squares in n+1 ways (so it's zero-indexed). Then it extracts the names, converts them to numeric, and selects the min. This will lose precision after about n = 64, at which point (most) R implementations would convert the sums to doubles. That could be saved by using a bigz implementation but that's not what we have to do here.

It also times out on TIO for n=10 because this is slow as all get-out.

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

175. PHP, 122 bytes, A000054

<?php
$n=file_get_contents('php://stdin');$s=0;for($i=0;$i<=$n;$i++){$s+=ord("DJIKHHIMIEJGGFIJJJHEGFIJG"[$i])-64;}echo $s;

Try it online!

Next sequence!

Uses delta encoding with the deltas represented by uppercase ASCII characters. The next sequence looks intimidating but it's just 1 at 0, 2 if sqrt(n) is an integer and 0 otherwise.

\$\endgroup\$
3
  • 2
    \$\begingroup\$ Note that hardcoding for less than 1000 digits is completely fine in this case, since this is a finite sequence, not an infinite one. \$\endgroup\$
    – Stephen
    Sep 22, 2017 at 12:49
  • 1
    \$\begingroup\$ @Stephen unless someone says that this should scrape the subway's website ;) \$\endgroup\$
    – Maya
    Sep 22, 2017 at 12:50
  • \$\begingroup\$ @NieDzejkob and OEIS has a broken link... \$\endgroup\$
    – KSmarts
    Sep 22, 2017 at 14:29
1
\$\begingroup\$

177. Lua, 214 bytes, A000184

function v(n)if n<1then return 1 end return v(~~~-n)*n end
function V(n)if n<1then return 1 end return V(~-~-n)*n end
function F(n)return math.floor(1/12*(2^(-~-~n+1)*V(-~(-~-~n<<1))/v(-~-~n-1)-3*4^-~-~n*-~-~n))end
\$\endgroup\$
4
  • \$\begingroup\$ dang, I was just testing out my PicoLisp implementation for this one, but it wasn't working on TIO...It's actually much simpler than the Maple implementation; using some gamma function identities, the formula provided by Mark van Hoeij simplifies to 2/3*GAMMA(2n)*(n+1/2)/(GAMMA(n)^2)-n*4^(n-1) where GAMMA(x)=factorial(x-1) \$\endgroup\$
    – Giuseppe
    Sep 22, 2017 at 13:29
  • 5
    \$\begingroup\$ Gotta love easy tagged sequences without a formula \$\endgroup\$
    – Stephen
    Sep 22, 2017 at 13:30
  • \$\begingroup\$ Come on! easy but no formula and no program, two out of three links are dead. \$\endgroup\$
    – Maya
    Sep 22, 2017 at 13:51
  • 1
    \$\begingroup\$ Good news is that the dead links are archived on web.archive.org \$\endgroup\$
    – Maya
    Sep 22, 2017 at 13:54
1
\$\begingroup\$

179. C (clang), 62 bytes, A000933

f(n){double c=(n>2)*~-~-n*~-~-~-n/3./4;return c+(c-(int)c>0);}
\$\endgroup\$
1
\$\begingroup\$

180. C (tcc), 63 bytes, A000062

#include <math.h>
int a(int n){
  return (n + 1) / (M_E - 2);
}

Try it online!

Next sequence!

Now since there is a lot of C versions, C must get the same treatment as Python.

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

181. C (clang), 276 bytes, A000063

long Factorial(n){return n<2?1:n*Factorial(n-1);}
Choose(n,k){return Factorial(n)/Factorial(k)/Factorial(n-k);}
Catalan(double n){return n-(int)n?0:(int)(1/(n+1.)*Choose(2*n,n));}
A000063(n){return Catalan(-~-~-~-~-~n/2-1)-Catalan(-~-~-~-~-~n/4.-1)-Catalan(-~-~-~-~-~n/6.-1);}
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Wait wasn't clang used for 180? \$\endgroup\$ Sep 23, 2017 at 18:01
  • 1
    \$\begingroup\$ @HusnainRaza but it wasn't used in the first 150 answers. On TIO there are 3 C compilers, so we can have at least 6 C answers. Yes, it's dumb, but valid. \$\endgroup\$
    – Maya
    Sep 23, 2017 at 18:11
1
\$\begingroup\$

182. Common Lisp, 134 bytes, A000276

(defun fact(n) (if (< n 2) 1 (* n (fact (1- n)))))
(defun a(n) (* (fact (+ n 3)) (1- (loop for k from 1 to (+ n 2) summing (/ 1 k)))))

Trival use of the formula specified by Detlefs on the OEIS page

Try it online!

Next sequence

\$\endgroup\$
4
  • \$\begingroup\$ Think this answer is invalid due to repeated language of last answer :( \$\endgroup\$ Sep 23, 2017 at 18:04
  • \$\begingroup\$ @HusnainRaza this is the second time Common Lisp has been used, that's OK \$\endgroup\$
    – Stephen
    Sep 23, 2017 at 18:16
  • \$\begingroup\$ @Stephen this is probably not what he meant but this is still valid \$\endgroup\$
    – Maya
    Sep 23, 2017 at 18:17
  • 1
    \$\begingroup\$ I think what he was trying to say is that this is invalid because it is chaining off answer 181, which is invalid because of language repeats. Still, that doesn't seem to be true. \$\endgroup\$ Sep 23, 2017 at 19:35
1
\$\begingroup\$

183. PostL, 61 bytes, A000134

INPUT PARSE 1 + C 3.1416 * 0.290498\ - FLR \ 1 \ 0 \ 2 - = +.

Try it online!

Next Sequence

_ is supposed to work in place of floor (or flr) but apparently it doesn't... hm

Walkthrough

INPUT PARSE 1 + C 3.1416 * 0.290498\ - FLR \ 1 \ 0 \ 2 - = +.  A000134
INPUT                                                          Take a line of input
      PARSE                                                    Parse to a double
            1                                                  Push 1
              +                                                Add top two elements
                C                                              Copy the zero-indexed number
                  3.1416                                       ~pi
                         *                                     Multiply top two elements
                           0.290498                            Thanks to Husnain Raza for this magic number
                                   \                           Swap the top two elements
                                     -                         Subtract the second from the top
                                       FLR                     Floor
                                           \                   Swap top two
                                             1                 Push 1
                                               \               Swap top two
                                                 0             Push 0
                                                   \           Swap top two
                                                     2         Push 2
                                                       -       Subtract the second from the top
                                                         =     Switch: 1 if x == 2 else 0
                                                           +.  Add top two and print
\$\endgroup\$
9
  • 1
    \$\begingroup\$ For 999 this returns 3142, but it should be 3141 \$\endgroup\$ Sep 23, 2017 at 19:53
  • \$\begingroup\$ Where did you get that formula? \$\endgroup\$
    – Maya
    Sep 23, 2017 at 20:19
  • \$\begingroup\$ the formula round(3.1416*n-0.790498) works for all n for 2<n<1000 \$\endgroup\$ Sep 23, 2017 at 22:05
  • \$\begingroup\$ @HusnainRaza Thanks for the revised formula edit it doesn't work for 1 -> 6 edit fixed \$\endgroup\$
    – hyper-neutrino
    Sep 23, 2017 at 23:49
  • 1
    \$\begingroup\$ @NieDzejkob, if you look at the Shanks paper, I think that line is supposed to correspond to equation 16, but it's missing an exponent of 2n. It also seems to simplify considerably to d(a,n) = d(b,n) m^(4n-1) prod_{p_i|m} (1 - jacobi(b, p_i) p_i^{-2n}) \$\endgroup\$ Sep 24, 2017 at 22:12
1
\$\begingroup\$

186. axo, 177 bytes, A000017

10=01=02=23=24=45=86=47=82*8=43*9=68*25*=825**25*1+=89+8*26*=725**6*[26*1+=][2*55*2*8*+[27*=][2*778**+[35*=][2*26*1+4*1+9*4*+[44*=][2*55447****+[44*1+=][3*288**1+84**-29*= }={ \

Try it online!

I'm aware that hardcoding is apparently "lame" but this took me like half an hour so I'm not gonna trash it ;P

This essentially hardcodes all of the values and puts them into the memory, then uses the = function to read the specific memory address and output it.

Next Sequence

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

187. SageMath, 321 bytes, A000177

import sage.combinat.partition
var('t', 's', 'isSquare')

def A000177(n):
  t = Partitions(n).list()
  s = 0
  for i in range(len(t)):
    if len(t[i])>6:
      continue
    isSquare = True
    for j in range(len(t[i])):
      if sqrt(t[i][j]) not in ZZ:
        isSquare = False
    if isSquare:
      s = s+1
  return s

Next Sequence

You can try it here.

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

192. Emoji, 326 bytes, A001824

📥👥🔚📤💬t💬📲💬1💬📥👥💬10💬📥🔀📤⛽👥💬t💬📱🐣🚘⛽👥💬n💬📲🔀👥💬a💬📲🔀👥👪💬4💬📥👪📤👥👫👪🔀💬n💬📱👥👫💬1💬📥🌊👥👪👥👪👪🌊💬a💬📱🔀💬n💬📱📤🚘🔃🔚🐧🐧🔙💬1💬📥🐧➡

Try it online!

Next sequence!

Abuses 📥 (floor) to convert a string to a number and 📤 (ceil) to increment. Also uses ints instead of booleans in conditionals, but the interpreter does seems to be okay with it. Uses the following formula: a(n) = 2*(4*n^2+1)*a(n-1) - (2*n-1)^4*a(n-2). The program operates on integers, but the language specification looks like only floats were supposed to be available. This allows computing the sequence infinitely without accuracy problems as the interpreter is implemented in Python.

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

197. D, 347 bytes, A000056

import std.stdio, std.conv;

void main(string[] args){
  int n = to!int(readln)+1;
  double x = 1;
  for(int i=2; i<n; i++){
    bool prime = true;
    for(int k=2; prime && k<=i/2; k++)
    {
        if(i%k==0)
        {
            prime=false;
        }
    }
    if(prime && n%i==0) { x = x*(1-1/(cast(double)i*i)); }
  }
  writeln(n*n*n*x);
}

Try it online!

Next Sequence.

Uses the formula a(n)=n*A007434(n), and the formula A007434(n) = n^2*Product_{p|n}(1-1/p^2).

\$\endgroup\$
3
  • \$\begingroup\$ Crude implementation of the next sequence in Python. It's ridiculously inefficient though. \$\endgroup\$ Oct 2, 2017 at 16:58
  • \$\begingroup\$ @icrieverytim That's because you wrote it in Python. \$\endgroup\$
    – KSmarts
    Oct 2, 2017 at 17:19
  • 1
    \$\begingroup\$ Oi, what do you get out of bashing Python for its speed? :P In any case, I realized I know all C-style languages to some extent, so I'm porting my solution to Go. Please don't ninja me, I'm on mobile. ;-; \$\endgroup\$ Oct 2, 2017 at 17:27
1
\$\begingroup\$

198. Go, 466 bytes, A000347

import . "math"

func A000347(n float64) int {
    result := 0

    n += 4

    for x_1 := 1.0; x_1 < n * n; x_1++ {
        for x_2 := x_1; x_2 < n * n; x_2++ {
            for x_3 := x_2; x_3 < n * n; x_3++ {
                for x_4 := x_3; x_4 < n * n; x_4++ {
                    if Sqrt(x_1) + Sqrt(x_2) + Sqrt(x_3) + Sqrt(x_4) <= n {
                        result += 1
                    }
                }
            }
        }
    }

    return result
}

Try it online!

Next sequence. (Easy.)

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

203. Julia 0.5, 96 bytes, A000050

function A000050(n)
x = 0:(2^n)
y = x'
z = x.^2 .+ y.^2
z = z[z .<= 2^n]
length(unique(z))-1
end

Try it online!

Next Sequence

Needs the -1 in length(unique(z))-1 because it always includes 0, which is not a positive integer.

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

216. BeanShell, 411 bytes, A000095

J(a,b){if(b<=0||(b%2)==0) return 0;j=1;if(a<0){a=-a;if((b%4)==3)j=-j;}while(a!=0){while((a%2)==0){a/=2;if((b%8)==3||(b%8)==5)j=-j;}t=a;a=b;b=t;if((a%4)==3&&(b%4)==3)j=-j;a=a%b;}if(b==1)return j;return 0;}n=new Scanner(System.in).nextInt()+1;l=(n==1)?1:0;if(n%4>0){l=(n%2>0)?1:2;for(d=3;d<=n;d+=2){if(n%d>0)continue;P=true;for(p=3;p*p<=d;p+=2)if(d%p==0){P=false;break;}if(!P)continue;l=l*(1+J(-1, d));}}print(l);

Also prints the input for some reason. I don't think it's possible to fix it

Try it online!

Next sequence!

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

230. Cubix, 86 bytes, A001147

................I?1O@.../s;.\...........*...............p..W/..../......?-2q:(*2O..W\p

Try it online!

Next sequence

Expands to the cube:

        . . . .
        . . . .
        . . . .
        . . . .
I ? 1 O @ . . . / s ; . \ . . .
. . . . . . . . * . . . . . . .
. . . . . . . . p . . W / . . .
. / . . . . . . ? - 2 q : ( * 2
        O . . W
        \ p . .
        . . . .
        . . . .
\$\endgroup\$
1
  • 1
    \$\begingroup\$ @NieDzejkob 86 byte answer just so we can all see your opus magnum. \$\endgroup\$
    – Giuseppe
    Oct 20, 2017 at 14:56
1
\$\begingroup\$

239. Boo, 346 bytes, A000429

import System.Numerics
def f(n as long,k as long):
 p=BigInteger(1);for i in range(n,n-k):p*=i
 if k>1:
  for i in range(k,1):p/=i
 return p
def b(n as long,i as long,k as long)as long:
 s=0;if n<1:return 1
 if i<1or k<1:return 0
 t=b(i-1,i-1,k-1);for j in range(0,n/i+1):s+=f(t+j-1,j)*b(n-i*j,i-1,k)
 return s
def a(n):
 return b(n,n,8)-b(n,n,7)

Next sequence!

Try it online!

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

285. Squirrel, 151 bytes, A000211

function A000211(input) {
if(input==0){
return 4;
}
if(input==1){
return 3;
}
if(input==2){
return 5;
}
return (A000211(input-1)+A000211(input-2)-2);
}

Try it online!

Didn't take much to learn this language!

Next Sequence!

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

282. Actually, 126 bytes, A011628

29*7+9*8+╝╛@%╗╜0=⌠00.ó⌡n10-1╛R⌠²╛@%╜=⌡cI"Did you know that Vim is vastly superior to every other existing editor? #flamewars"X

Try it online!

Next sequence!

Explanation

29*7+9*8+╝╛@%╗╜0=⌠00.ó⌡n10-1╛R⌠²╛@%╜=⌡cI
29*7+9*8+╝                               Put 233 in the second register
          ╛@%╗                           Calculate input%233 and put it in the
                                         first register (I'll call this n)
              ╜0=⌠00.ó⌡n                 If n is 0, output 0 and exit
                            ╛R⌠      ⌡c  Count integers smaller or equal to 233...
                               ²         such that their squares
                                ╛@%      are congruent modulo 233
                                   ╜=    to the input.
                                       I If there is at least one such integer
                                         (i. e. n is a quadratic residue mod 233)
                           1             then output 1,
                        10-              otherwise, output -1
\$\endgroup\$
4
  • 1
    \$\begingroup\$ The resut for n=2 seems wrong (and from the description, I don't understand how it gets the right result for n=7) \$\endgroup\$ Dec 24, 2017 at 18:30
  • \$\begingroup\$ Unintuitive operand order got me during a last minute change... hang on \$\endgroup\$
    – Maya
    Dec 25, 2017 at 9:26
  • \$\begingroup\$ The explanation claims you count how many numbers <=n have square congruent to n. I guess that's really something like <=233. (BTW, there will always be two square roots.) \$\endgroup\$ Dec 25, 2017 at 10:49
  • \$\begingroup\$ @ChristianSievers that's right, I made a mistake when rereading the code, fixed ;) \$\endgroup\$
    – Maya
    Dec 25, 2017 at 11:59
1
\$\begingroup\$

286. Pyon, 1118 bytes, A000151

from fractions import Fraction

def tofrac(a):
	global Fraction
	return [Fraction(x) for x in a]

# a(x)*b(x), first n terms
def mul(a, b, n):
	x=[0] * min(n, len(a) + len(b) - 1)
	for i in range(min(n, len(a))):
		for j in range(min(n - i, len(b))):
			x[i + j] += a[i] * b[j]
	return x

# a(x^e), first n terms
def powarg(a, e, n):
	return [0 if i % e else a[i // e] for i in range(n)]

# c*a(x)
def mulc(a,c):
	return [x * c for x in a]

def divcfrac(a,c):
	return [x / c for x in a]

# a(x) + b(x)
def add(a,b):
	return [(a[i] if i < len(a) else 0) + (b[i] if i < len(b) else 0) for i in range(max(len(a), len(b)))]

# a'(x)
def polyderiv(a):
	return [i * x for i, x in enumerate(a)][1:]

# f(x)*exp(g(x)), coefficient of x^n
def exptaylor(f,g,n):
	global add, polyderiv, mul
	fac = 1
	for i in range(n):
		f=add(polyderiv(f), mul(f, polyderiv(g), n))
		fac *= i + 1
	return f[0].numerator // fac

R = [0, 1]

for n in range(len(R), int(input()) + 2):
	P = []
	for k in range(1, n):
		d = divcfrac([Fraction(x) for x in powarg(R, k, n)], k)
		P = add(P, d)
	R.append(exptaylor([0, 1], mulc(P, 2), n))

print(R[-1])

Try it online!

Next sequence!

\$\endgroup\$

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.