# One OEIS after another

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:

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

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

code

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

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>

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

# 268. Pyke, 99 bytes, A000338

9 2/Q2+X*15 2/Q2+*-BQ1>*Q0q5*Q1q18*++


Try it here!

Next sequence. (quite tendious, yet doable I think)

• The next sequence is definitely doable. It looks more tedious than hard to me. – KSmarts Nov 30 '17 at 19:38

# 269. Pip, 118 bytes, A000099

n:0
m:0
++a
W a {
++n
Y -n\,n
AA:{$+a*a<=n} MS yCPy VV:PI*n PP:AA-VV I ABPP>m { m:ABPP --a } } n  Try it online! (times out for indices greater than 7) Next sequence ### Commented Implements the definition of the sequence: n:0 Index of helper sequences m:0 Max value of |P(n)| so far ++a Index of main sequence (++ because the definition is 1-indexed) W a { Count down until a hits 0: ++n Increment index of helper sequence Y -n\,n Yank inclusive range [-n, n] AA: Sequence A(n) is: {$+a*a<=n}   Function: Square items of list, sum, and check <= n
MS           Map-sum
yCPy         Cartesian product of y with itself
VV:PI*n       Sequence V(n) is pi times n
PP:AA-VV      Sequence P(n) is A(n)-V(n)
I ABPP>m {    If abs(P(n)) > current max value:
m:ABPP       Max is abs(P(n))
--a          Decrement index of main sequence
}
}
n              Output index of helper sequence at the a'th maximum

• Did you check that the Pi constant has enough accuracy to compute 1000 terms? – NieDzejkob Nov 30 '17 at 21:32
• @NieDzejkob I believe it will. It's got about 16 significant digits, and if the series is ~= 0.0139 * n^4 (which is a pretty good fit for the first 200 terms), it should only require 11 significant digits to compute n = 1000. But I would have to compute that many terms to find out, and that would take days. Maybe I could write a C program to check... – DLosc Nov 30 '17 at 21:48

# 134. Emoji, 277 bytes, A000643

📥💬i💬📲
💬0💬📥👥
⛽
💬i💬📱👥💬1💬📥🌊💬i💬📲💬1💬📥🐔
🚘⛽
💬1💬📥⛽
🔀👥💬1💬📥🌊🔀💬0💬📥🐔
🚘⛽
🔀💬2💬📥👪
🚘🔃🔚🐧🔀👥💬t💬📲👫💬t💬📱
🚘🔃🔀➡


Try it online!

Next sequence!

Explanation:

In contrast to Emojicode, Emoji is an esoteric programming language. Emoji is similar to GolfScript and CJam in that it uses a stack as the primary memory.

		Implicitly push all arguments as string. Stack: "7"
📥		Floor. Normally 🔢 would be used to get a float, but using
floor gives an int, which (since the interpreter is written
in Python) is a bignum. Stack: 7
💬i💬📲		Store to variable i. Stack:
💬0💬📥👥		Push "0", to string, duplicate. Stack: a(1) a(0)
⛽...🚘⛽...🚘🔃	While(...) do ... (let's look later in the loop)
💬i💬📱		(in while condition) recall variable i. Stack: a(4) a(3) i
👥		Duplicate. Stack: a(4) a(3) i i
💬1💬📥🌊		Subtract 1. Stack: a(4) a(3) i i-1
💬i💬📲		Store i-1 to i for next iteration. Stack: a(4) a(3) i
💬1💬📥🐔		Is greater than 1? This means that the outer loop will be
repeated n - 1 times, where n is the input.
Stack: a(4) a(3) true
💬1💬📥		(in outer loop) Now we will calculate 2^a(3) - push 1.
Stack: a(4) a(3) 1
⛽...🚘⛽...🚘🔃	While(...) do ... (now a(3) is the loop counter, let's assume
we are at the last iteration of this loop.)
🔀		Swap. Stack: a(4) 2^(a(3)-1) 1
👥		Duplicate. Stack: a(4) 2^(a(3)-1) 1 1
💬1💬📥🌊		Subtract 1. Stack: a(4) 2^(a(3)-1) 1 0
🔀		Swap. Stack: a(4) 2^(a(3)-1) 0 1
💬0💬📥🐔		Is greater than 0? This means that the inner loop will be
repeated a(3) times. Stack: a(4) 2^(a(3)-1) 0 true. Notice
that after true is popped, the two values are swapped compared
to the beginning of the condition evaluation. This has to be
fixed both in the inner loop and after it.
🔀		(in inner loop) swap. Stack: a(4) 0 2^(a(3)-1)
💬2💬📥👪		Multiply by 2. Stack: a(4) 0 2^a(3).
The loop ends. Stack: a(4) 2^a(3) 0
🔚🐧		The counter is now always 0 and has to be discarded. Since
there is no such instruction, an empty if is used instead.
Stack: a(4) 2^a(3)
🔀		Swap. Stack: 2^a(3) a(4)
👥💬t💬📲		Duplicate and store a(4) in t. Stack: 2^a(3) a(4)
💬t💬📱		Restore a(4) from variable. Stack: a(5) a(4).
The loop ends here. Stack: a(7) a(6).
🔀		Swap. Stack: a(6) a(7).
➡		Print a(7). The stack is discarded at the end of the program.


Emoji aren't fixed-width in a fixed-width font, so spaces don't work for alignment. Fortunately, tabs work, but different emoji fonts might slightly break it.

• ಠ_ಠ I have a feeling that you might get the bounty when it's finally awarded :P – caird coinheringaahing Sep 4 '17 at 9:58
• @cairdcoinheringaahing Unless someone posts an answer in Malbolge, a. k. a. you are probably right. Have you seen 99 bottles of beer in this? – NieDzejkob Sep 4 '17 at 10:50

# 143. Excel, 120 bytes, A000782

=2*FACT(2*A1)/(FACT(A1)*(FACT(A1+1)))-IFERROR(FACT(2*A1-2)/(FACT(A1-1)*(FACT(A1))),0)


Next sequence!

Input is in cell A1. It just implements the function listed on OEIS:

a(n) = 2 * C(n) - C(n-1)
C(n) = (2n)! / (n!(n+1)!)


Technically, only n > 0 should be valid so the IFERROR bit could be dropped since it only errors on n < 1. I left it in for artistic license and to have what I think is a more interesting next sequence.

# 200. shortC, 189 bytes, A000092

Note: byte count includes the +3 bytes for -lm.

f(x){Lr=0,d=0,n=1;O;d<x+1;n++){Lc=0,m=ceil(sqrt(n))+1,i=-m,j,k;O;i<m;i++)Oj=-m;j<m;j++)Ok=-m;k<m;k++)c+=i*i+j*j+k*k<=n;c-=lround(sqrt(n*n*n)*4.18879020478639);c=abs(c);Fc>r)d++,r=c;}Tn-1


Try it online!

Next sequence!

• For the next sequence, x < n (modulo implies it but it wasn't immediately obvious to me). – NieDzejkob Oct 2 '17 at 21:37
• Well, that's 200. I'm not sure whether to be glad or astounded that anyone still cares about this challenge :P – caird coinheringaahing Oct 2 '17 at 21:51
• @cairdcoinheringaahing that means that you came up with an interesting challenge. You should be proud. – NieDzejkob Oct 3 '17 at 10:31

# 201. Nim, 213 bytes, A000189

from strutils import parseint
import math

proc A000189(index: int): int =
result=1
for x in 1..index-1:
if x^3 mod index == 0:
result = result + 1
return



Try it online!

Next Sequence.

• Darn I had a Brain-Flak solution coming :P Oh well it was nowhere near done anyway xD – hyper-neutrino Oct 2 '17 at 22:58

# 274. ArnoldC, 1021 bytes, A000123

IT'S SHOWTIME
HEY CHRISTMAS TREE INPUT
YOU SET US UP @I LIED
HEY CHRISTMAS TREE OUTPUT
YOU SET US UP @I LIED
GET YOUR ASS TO MARS INPUT
DO IT NOW
I WANT TO ASK YOU A BUNCH OF QUESTIONS AND I WANT TO HAVE THEM ANSWERED IMMEDIATELY
GET YOUR ASS TO MARS OUTPUT
DO IT NOW A000123 INPUT
TALK TO THE HAND OUTPUT
YOU HAVE BEEN TERMINATED

LISTEN TO ME VERY CAREFULLY A000123
GIVE THESE PEOPLE AIR
HEY CHRISTMAS TREE NUMBER1
YOU SET US UP @NO PROBLEMO
HEY CHRISTMAS TREE NUMBER2
YOU SET US UP @NO PROBLEMO
BECAUSE I'M GOING TO SAY PLEASE INDEX
GET TO THE CHOPPER NUMBER1
HERE IS MY INVITATION INDEX
GET DOWN 1
ENOUGH TALK
GET TO THE CHOPPER NUMBER2
HERE IS MY INVITATION INDEX
ENOUGH TALK
GET YOUR ASS TO MARS NUMBER1
DO IT NOW A000123 NUMBER1
GET YOUR ASS TO MARS NUMBER2
DO IT NOW A000123 NUMBER2
GET TO THE CHOPPER NUMBER1
HERE IS MY INVITATION NUMBER1
GET UP NUMBER2
ENOUGH TALK
YOU HAVE NO RESPECT FOR LOGIC
I'LL BE BACK NUMBER1
HASTA LA VISTA, BABY


Try it online!

Next Sequence

Uses the recurrence relation a(n) = a(n-1) + a(floor(n/2))

# 272. SNOBOL4 (CSNOBOL4), 129 bytes, A010008

	INPUT('READLINE', 5)
OUTPUT('PRINT', 6)
EQ(IN,0)			:S(OK)
OUTPUT = 18 * IN * IN + 2	:(END)
OK
OUTPUT = 1
END


Try it online!

Next sequence

I think I could probably write another answer in SNOBOL; it took me a good ten minutes to figure out how to do I/O because I'm dumb, and I'm lucky the sequence was so stupidly easy.

Explanation:

SNOBOL is pretty old, so it has some weird quirks for someone who's been using more "modern" languages. First of all, you have to indent lines, because un-indented lines are labels. Control flow is purely through GOTOs, labels, and SUCCESS/FAILURE of a line. And I'm still not sure about how to write a comment.

INPUT('READLINE', 5) sets a variable READLINE that takes input from file 5, which is by default the keyboard/console input.

IN = READLINE reads a single line from the file as a string.

OUTPUT('PRINT', 6) sets a variable PRINT that prints to file 6, which is by default the console.

EQ(IN,0) tests for equality between the input and 0. The GOTO:S(OK) is the instruction "on Success, goto OK", so it jumps to OK, setting OUTPUT to 1, printing, and then hitting END.

Otherwise, it sets the output to 18*n^2+2 and jumps to the END, terminating the program.

• I've heard that that kind of control flow is considered harmful. – KSmarts Dec 7 '17 at 20:25

# 278. Java 6, 5692 bytes, A000104

import java.util.List;
import java.util.ArrayList;
import java.util.Set;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;

final class Main {
static final Set<Pair> offsets;

static {
offsets = new HashSet<Pair>();
}

static final class Pair {
final int x, y;

Pair(int x, int y) {
this.x = x;
this.y = y;
}

public String toString() {
return "(" + this.x + ", " + this.y + ")";
}

public boolean equals(Object other) {
if (other == null) {
return false;
} else if (other instanceof Pair) {
Pair pair = (Pair) other;
return this.x == pair.x && this.y == pair.y;
} else {
return false;
}
}

public int hashCode() {
return this.x ^ this.y; // Expect many collisions with this hashcode; it's mostly just to make sure the hashset actually checks for equality) //
}

return new Pair(this.x + pair.x, this.y + pair.y);
}
}

private Main() {}

public static Set<Pair> rotate(Set<Pair> polyomino) {
Set<Pair> result = new HashSet<Pair>();
for (Pair pair : polyomino)
return result;
}

public static Set<Pair> conjugate(Set<Pair> polyomino) {
Set<Pair> result = new HashSet<Pair>();
for (Pair pair : polyomino)
return result;
}

public static List<Set<Pair>> variants(Set<Pair> polyomino) {
List<Set<Pair>> results = new ArrayList<Set<Pair>>();
for (int x = 0; x < 4; x++) {
polyomino = rotate(polyomino);
}
return results;
}

public static Set<Integer> x(Set<Pair> polyomino) {
Set<Integer> results = new HashSet<Integer>();
for (Pair pair : polyomino)
return results;
}

public static Set<Integer> y(Set<Pair> polyomino) {
Set<Integer> results = new HashSet<Integer>();
for (Pair pair : polyomino)
return results;
}

public static int max(Set<Integer> set) {
if (set.size() == 0) throw new IllegalArgumentException("max arg is an empty sequence");
Iterator<Integer> iterator = set.iterator();
int max = iterator.next();
while (iterator.hasNext()) {
int value = iterator.next();
max = max > value ? max : value;
}
return max;
}

public static int min(Set<Integer> set) {
if (set.size() == 0) throw new IllegalArgumentException("min arg is an empty sequence");
Iterator<Integer> iterator = set.iterator();
int min = iterator.next();
while (iterator.hasNext()) {
int value = iterator.next();
min = min < value ? min : value;
}
return min;
}

public static Pair corner(Set<Pair> polyomino) {
return new Pair(min(x(polyomino)), min(y(polyomino)));
}

public static Set<Pair> normalize(Set<Pair> polyomino) {
Pair cn = corner(polyomino);
Set<Pair> results = new HashSet<Pair>();
for (Pair pair : polyomino)
results.add(new Pair(pair.x - cn.x, pair.y - cn.y));
return results;
}

public static boolean translations(Set<Pair> p1, Set<Pair> p2) {
return normalize(p1).equals(normalize(p2));
}

public static boolean isomorphic(Set<Pair> p1, Set<Pair> p2) {
for (Set<Pair> p : variants(p1))
if (translations(p, p2))
return true;
return false;
}

public static boolean filled(Set<Pair> polyomino) {
Set<Integer> x = x(polyomino);
Set<Integer> y = y(polyomino);
for (int i = min(x) + 1; i < max(x); i++) {
for (int j = min(y) + 1; j < max(y); j++) {
if (!polyomino.contains(new Pair(i, j))
&&   polyomino.contains(new Pair(i, j + 1))
&&   polyomino.contains(new Pair(i, j - 1))
&&   polyomino.contains(new Pair(i + 1, j))
&&   polyomino.contains(new Pair(i - 1, j)))
return false;
}
}
return true;
}

public static List<Set<Pair>> polyominoes(int cells) {
List<Set<Pair>> results = new ArrayList<Set<Pair>>();
if (cells == 0) {
return results;
} else if (cells == 1) {
Set<Pair> set = new HashSet<Pair>();
return results;
} else if (cells == 2) {
Set<Pair> set = new HashSet<Pair>();
return results;
} else {
for (Set<Pair> polyomino : polyominoes(cells - 1)) {
for (Pair cell : polyomino) {
for (Pair offset : offsets) {
Set<Pair> variant = new HashSet<Pair>(polyomino);
if (variant.size() == cells) {
}
}
}
}
}
List<Set<Pair>> output = new ArrayList<Set<Pair>>();
outer: for (Set<Pair> r : results) {
for (Set<Pair> p : output) {
if (isomorphic(r, p)) {
continue outer;
}
}
}
return output;
}

public static void main(String[] args) {
boolean visualizer = true; // Change to false to not show visualizations
int cells;
List<Set<Pair>> polyominoes = polyominoes(cells = new Scanner(System.in).nextInt());
System.out.println(polyominoes.size());
if (cells != 0 && visualizer) {
System.out.println();
for (Set<Pair> polyomino : polyominoes) {
Set<Integer> x = x(polyomino);
Set<Integer> y = y(polyomino);
int minx = min(x), maxx = max(x);
int miny = min(y), maxy = max(y);
for (int i = minx; i <= maxx; i++) {
for (int j = miny; j <= maxy; j++) {
System.out.print(polyomino.contains(new Pair(i, j)) ? '#' : '.');
} System.out.println();
} System.out.println();
}
}
}
}


Try it online!

The TIO link links to the Java 8 interpreter but this answer works on Java 6 (tested locally thanks to user202729).

Next Sequence - this one has enough terms to be hardcoded but please don't.

Originally programmed in Python

• Not enough. You need to support all n not "larger than 1000" - it means that all n such that 0 ≤ n ≤ 1000 need to be supported, that's 1001 terms. You are off by 1. – user202729 Dec 13 '17 at 14:45
• @user202729 lol oh. well, it's close :P In that case then, hardcoding it would require getting 1001 in which case one might as well solve it the correct way :p – hyper-neutrino Dec 13 '17 at 14:48
• rules for the next sequence can be found here on page 13 since the OEIS page links to a JSTOR page and I didn't feel like registering there. – Giuseppe Dec 13 '17 at 14:48
• HyperNeutrino: Do you want to turn off the visualizer? – user202729 Dec 13 '17 at 14:49
• @user202729 No, I intentionally left it on. I don't think it makes the output invalid since it obviously gives the correct answer, but if you want, I can turn it off; I can easily keep the bytecount the same. – hyper-neutrino Dec 13 '17 at 14:52

# 284. Hexagony, 211 bytes, A000384

     ? } 2 \ . .
. . . " . . .
. @ ! * = < . .
. . . > ( { / . .
. . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . .
. . . . . . . . .
. . . . . . . .
. . . . . . .
. . . . . .


Try it online!

Next sequence!

What better language is there to compute hexagonal numbers?

### Explanation

I decided to make this code use each character (except ., space and newline) only once, because I had too much time on my hands. Let's label the edge the MP starts on A, the one to the left of it L and the one to the right - R. The following linear code gets executed:

?}2"*({=*!@
?           A = input()
}2         R = 2
"*       L = A * R = 2 * n
(      L = L - 1 = 2 * n - 1
{=*   R = A * L = n(2n-1) = a(n)
!  Print the result
@ End execution


# 258. Forth (gforth), 329 bytes, A000144

: ODDQ 2 MOD ;
: EVENQ 1+ ODDQ ;
: DIVOK /MOD SWAP IF DROP 0 ELSE ODDQ THEN ;
: A2131 DUP 1+ 0 SWAP 1 ?DO OVER I DIVOK IF I + THEN LOOP NIP ;
: A186690 DUP A2131 SWAP EVENQ IF 0 SWAP - THEN ;
: ADVANCE DUP 1+ 0 SWAP 1 ?DO I 1+ PICK I A186690 * + LOOP 20 * OVER / SWAP 1+ ;
: A144 1 SWAP 1 SWAP 0 ?DO ADVANCE LOOP 1 ?DO NIP LOOP ;


Try it online!

Next sequence!

This time I managed to remove the surplus elements from the stack with 1 ?DO NIP LOOP.

• Learn a new language just to use it twice... – user202729 Nov 21 '17 at 9:55
• @user202729 no, I learned it for a much larger project. It involves bootstrapping Linux from less than 1K binaries, and Forth is a good language thanks for its small interpreter. – NieDzejkob Nov 21 '17 at 10:36
• I'm worried about the accuracy of the solution of the next sequence... This Jelly solution only survive up to n=13. – user202729 Nov 21 '17 at 10:38
• and is non-esoteric. BF interpreter is also small. – user202729 Nov 21 '17 at 10:39
• But why don't you just use assembly? – user202729 Nov 21 '17 at 10:42

# 295. Unefunge-98 (PyFunge), 133 bytes, A000218

#z3&#rz#;::/3*j$.@1-\:a%:*\a/:a%:*\a/:*++\#;r print(*map(lambda x:'pHra ywe!NY'[int(x, 16)], '%x'%(3*7*8*1821847*279590039)), sep='')  Next sequence! Try it online! #z3&#rz#;::/3*j$.@1-\:a%:*\a/:a%:*\a/:*++\#;r
#z                                            Kind of serves no purpose...
3                                           Starting number of the sequence
&                                          Input the number of iterations
beginning
::/                                  Make a copy of the loop counter and
divide it by itself. Since 0/0 is
defined as 0 in Funge, this leaves
1 on the stack when the loop
counter is not zero, but 0 when it
is
3*                                Multiply the result by 3 to skip
$.@$.@                             When the loop ends, print the
result
1-                           Decrement the loop counter
\:a%:*\a/:a%:*\a/:*++\     Calculate the next element of the
sequence.

• +1 for a Python polyglot! (For anyone reading this, try running it in Python 3) – caird coinheringaahing Dec 31 '17 at 23:02
• Befure running it, try to look and guess what it does. Should be easy to guess even if you don't know Python. – user202729 Jan 1 '18 at 4:06

# 306. Python 3, 2113 bytes, A000145

def intsqrt(n):
if n == 0: return 0
counter, temp = 1, 1
while counter < n:
counter <<= 2
temp <<= 1
oldtemp1, oldtemp2 = 0, 0
while oldtemp2 != temp and temp > 0:
oldtemp2, oldtemp1, temp = oldtemp1, temp, (temp + n // temp) >> 1
return oldtemp1

def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)

def GenerateSquareSequence(n):
s = 0
for a in range(intsqrt(n), -1, -1):
for b in range(min(a, intsqrt(n - a*a)), -1, -1):
for c in range(min(a, b, intsqrt(n - a*a - b*b)), -1, -1):
for d in range(min(a, b, c, intsqrt(n - a*a - b*b - c*c)), -1, -1):
for e in range(min(a, b, c, d, intsqrt(n - a*a - b*b - c*c - d*d)), -1, -1):
for f in range(min(a, b, c, d, e, intsqrt(n - a*a - b*b - c*c - d*d - e*e)), -1, -1):
for g in range(min(a, b, c, d, e, f, intsqrt(n - a*a - b*b - c*c - d*d - e*e - f*f)), -1, -1):
for h in range(min(a, b, c, d, e, f, g, intsqrt(n - a*a - b*b - c*c - d*d - e*e - f*f - g*g)), -1, -1):
for i in range(min(a, b, c, d, e, f, g, h, intsqrt(n - a*a - b*b - c*c - d*d - e*e - f*f - g*g - h*h)), -1, -1):
for j in range(min(a, b, c, d, e, f, g, h, i, intsqrt(n - a*a - b*b - c*c - d*d - e*e - f*f - g*g - h*h - i*i)), -1, -1):
for k in range(min(a, b, c, d, e, f, g, h, i, j, intsqrt(n - a*a - b*b - c*c - d*d - e*e - f*f - g*g - h*h - i*i - j*j)), -1, -1):
for l in range(min(a, b, c, d, e, f, g, h, i, j, k, intsqrt(n - a*a - b*b - c*c - d*d - e*e - f*f - g*g - h*h - i*i - j*j - k*k)), -1, -1):
if a*a + b*b + c*c + d*d + e*e + f*f + g*g + h*h + i*i + j*j + k*k + l*l == n:
t = (a, b, c, d, e, f, g, h, i, j, k, l)
u = []
for m in range(0, 4096):
v = [t[o] * (-1)**(m >> o) for o in range(0, 12)]
u.append(repr(sorted(v)))
w = set(u)
x = [eval(y) for y in w]
for z in x:
p = [z.count(o) for o in set(z)]
q = 479001600
for r in p:
q = q // factorial(r)
s += q
return s


Try it online!

Next sequence: A002113: palindromic number

Sorry for the counting by exhaustion algorithm (and the 14-layer for loop), but the sequence also counts representations with negative numbers into the total.

• ... and for using Python. – user202729 Jan 8 '18 at 5:20
• (of course, anyone is free to use any language, just saying) – user202729 Jan 8 '18 at 5:27
• ... and for CamelCase function name. – NieDzejkob Jan 8 '18 at 13:53

# 307. Scratch 2, 6060 bytes, A002113

Try it online!

Next Sequence

Relevant part:

"scripts": [[639, 148.5, [["letter:of:", 1, ["readVariable", "is_palindrome"]]]],
[59,
92,
[["whenGreenFlag"],
["deleteLine:ofList:", "all", "palindromes"],
["setVar:to:", "counter", 0],
["doUntil",
[["setVar:to:", "is_palindrome", "1"],
["setVar:to:", "i", 0],
["doRepeat",
[["doIf",
["not",
["=",
["letter:of:",
[["setVar:to:", "is_palindrome", 0]]],
["changeVar:by:", "i", 1]]],
["doIf",
["changeVar:by:", "counter", 1]]]]]],


Full code: https://pastebin.com/jEc5W0SL

• ... why is this one 1-indexing? – user202729 Jan 8 '18 at 8:50
• It seems too slow... – user202729 Jan 8 '18 at 8:51
• Could you make sure the offset is right? For instance, input 0 should give you an output of 0. I can't check this since something's wrong with flash in my browser. (since user202729 seems to be saying something) – NieDzejkob Jan 8 '18 at 15:13
• I've managed to get Flash to work, and this is unfortunately slightly invalid due to the rules about indexing sequences. For example, for all numbers less than 10 the program should output the index. Changing n to n-1 should fix this – NieDzejkob Jan 9 '18 at 16:00

# 311. ALGOL 68 (Genie), 334 bytes, A000148

BEGIN
LONG LONG INT n   := read int + 2;
LONG LONG INT r   := 0;
LONG LONG REAL ma := ( n / 2.0 ) ** 1.5;
LONG LONG REAL x  := 2.0 / 3;
INT a             := 1;
WHILE a <= ma DO
INT b := a;
WHILE a ** x + b ** x <= n DO
r := r + 1;
b := b + 1
OD;
a := a + 1
OD;
print ( whole ( r , 0 ) )
END


Next Sequence

Try it online!

• C (gcc) is allowed right now (2018-01-09), right? – SIGSTACKFAULT Jan 9 '18 at 18:46
• @Blacksilver looks like it, it's only been used twice so far. – Giuseppe Jan 9 '18 at 18:55

# 312. Python 2 (PyPy), 1811 bytes, A000334

partition_result_set = []
location_result_set = []
big_max = 1

def p_value(coord, value):
global big_max
i = value
for d in coord:
i = i * big_max + d
return i

def partition(number, max, row = []):
global partition_result_set
if number == 0:
partition_result_set[len(row) - 1] += [row]
return

for i in range(max, 0, -1):
if number >= i:
partition(number - i, i, row + [i])

def init_partitions(number):
global partition_result_set
for i in range(number):
partition_result_set += [[]]

partition(number, number)

def enumerate_locations(number_of_blocks, dimension, have_locations = [], possible_locations = []):
global g, result_set, y, big_max, partition_result_set, location_result_set

if possible_locations == []:
possible_locations = [[0] * dimension]
y = [0] * number_of_blocks
temp = number_of_blocks
while temp > 0:
big_max *= 10
temp //= 10

for location in possible_locations:
new_have_locations = have_locations + [location]
new_possible_locations = [l for l in possible_locations if l != location]
for i in range(dimension):
m = [location[d] + (1 if i == d else 0) for d in range(dimension)]
is_ok = True
for j in range(dimension):
n = [m[d] - (1 if j == d else 0) for d in range(dimension)]
if [d for d in n if d < 0] == [] and n not in new_have_locations: is_ok = False
if is_ok: new_possible_locations += [m]

len1 = len(new_have_locations)
for x in partition_result_set[len1 - 1]:
location_result_set += [repr(sorted([p_value(new_have_locations[k], x[k]) for k in range(len1)]))]
if number_of_blocks > 1:
enumerate_locations(number_of_blocks - 1, dimension, new_have_locations, new_possible_locations)

def A000334(n):
init_partitions(n + 1)
enumerate_locations(n + 1, 4)
print len(set(location_result_set))


Try it online!

Next sequence: A001811, Laguerre Polynomial. At least there is a closed-form formula

Sorry for Python again, but when the question comes to enumeration I think Python is the easiest way to deal the question with.

# 313. PowerShell, 146 bytes, A001811

function A001811($n){ [System.Numerics.BigInteger]$a=1;
for ($i=1;$i -le $n;$i++) {
$a=$a*($i+4)*($i+4)/$i } return$a
}


Online test suite

Next sequence: A000146

# 322. Mathematica (10.1), 150 bytes, A000249

Symbol[StringJoin[FromCharacterCode[72], FromCharacterCode[101], FromCharacterCode[97], FromCharacterCode[100]]][#(****)&][Round[BesselK[Slot[1], 5]]]


Next sequence

A bit over-the-top due to the character requirement. Effectively the same as Round[#~BesselK~5]&.

• I was confused by (****) for a bit, until I remembered that Mathematica comment is (* ... *)... – user202729 Jan 26 '18 at 14:24

# 330. Shakespeare Programming Language, 1854 bytes, A000155

Ye A000155 program.
Ajax, a of n minus four.
Brutus, a of n minus three.
Cicero, a of n minus two.
Dogberry, a of n minus one.
Isabella, input.
Miranda, counter.
Timon, a of n.

Act I: TBD.
Scene I: Taking input.

[Enter Isabella and Timon]

Timon:
Listen to your heart! Are you worse than the sum of a big old cat and
a pig?

Isabella:
If so, you are me.

Timon:
If so, let us proceed to Act II. Are you as bad as the sum of a furry
black cat and a pig?

Isabella:
If so, you are the sum of a beautiful trustworthy handsome pony and a
coward.

Timon:
If so, let us proceed to Act II.

[Exeunt Isabella and Timon]
[Enter Brutus and Cicero]

Brutus:
You are a big chihuahua.

Cicero:
You are a horse.

[Exeunt Brutus and Cicero]
[Enter Dogberry and Miranda]

Miranda:
You are the sum of a amazing brave beautiful angel and a hog!

Dogberry:
You are a pretty cute pony.

[Exit Dogberry]
[Enter Timon]

Scene II: The loop.

Miranda:
You are the sum of Ajax and the product of a sunny sky and the sum of
the product of Brutus and the difference between me and the sum of an
animal and a delicious cow and the product of Dogberry and the sum of
me and a toad. Am I as big as Isabella?

Timon:
If so, let us proceed to Scene III.

[Exit Timon]
[Enter Ajax]

Ajax:
You are the sum of you and a lantern.

Miranda:
You are Brutus.

[Exeunt Ajax and Miranda]
[Enter Brutus and Cicero]

Cicero:
You are me.

Brutus:
You are Dogberry.

[Exeunt Brutus and Cicero]
[Enter Dogberry and Timon]

Timon:
You are me.

[Exit Dogberry]
[Enter Miranda]

Miranda:

Scene III: TBD.

[Exit Miranda]
[Enter Isabella]

Act II: Finishing up.
Scene I: Output.

Isabella: Open thy heart!
[Exeunt]


Try it online!

Next sequence!

• Just when I was almost finished actually implementing the Bessel functions... – KSmarts Jan 30 '18 at 15:40
• I just realised that I forgot to fill in the act and scene titles... – NieDzejkob Feb 5 '18 at 14:23

# 335. Python 2 (Cython), 620 bytes, A000157

from itertools import*
from math import*
from functools import*
n=int(input())+1#offset 1
for p in permutations(range(n)):
for i in range(2**n):#inversion
v=[0]*(2**n)#visited
c=0#number of cycles
e=1#all is even
for x in range(2**n):
if v[x]:continue
w=1#1 if this cycle is even
while 1>v[x]:
v[x]=1;w^=1
x=reduce(lambda x,y:x+x+y,[1&(x>>s)for s in p])^i
e&=w;c+=1
a+=2**c*(1+e)
print(a//(2**n*factorial(n)*4))

#Come on... it's not that hard.
#Time complexity: 4**n*factorial(n)
#Memory complexity: 2**n
#(which is actually order of magnitude
#faster than the naive algorithm)


Try it online!

Next sequence

Originally intended to work in Python3, but Python 3 (Cython) raises an error "deallocating None".

Sorry for using Python, but programming on mobile is not easy. Posted 2 days ago in chat while waiting for someone else to post, probably with another language.

The next sequence has some chemistry-related things, but the recurrence relation is easy to implement. Ideally I hope someone will explain what the sequence is about. (I don't even explain most of my own answers...)

(Side note: Syntax highlighting fails for some comments)

• Well done! You can compute c (and e) without explicitely looking at all possible inputs using linear algebra similar to what I did in answer no. 178 – Christian Sievers Feb 17 '18 at 9:03
• Talking of "what the sequence is about", what's A000157 really? It's obviously not what the title says, but equivalence classes of some kind. – Peter Taylor Feb 17 '18 at 9:17
• I actually didn't read the paper, and I think the description of the other sequence is easier to understand, and my first try got it correctly. So I just calculate and halve the other sequence. – user202729 Feb 17 '18 at 9:25
• @PeterTaylor After having read 3 papers in the A370 sequence I still can't find any reference to this sequence. No idea. – user202729 Feb 17 '18 at 9:44

# 346. C++14 (gcc), 3780 bytes, A000162

// oeis

#ifndef _GLIBCXX_DEBUG
#define NDEBUG
#endif
#include <cassert>

#include<iostream>
#include<vector>
#include<algorithm>

using v1=std::vector<char>;
using v2=std::vector<v1>;
using v3=std::vector<v2>;

template<class Ar>Ar zip(Ar const& a){
Ar result(a[0].size());
for(size_t y=a[0].size();y-->0;){
result[y].resize(a.size());
for(size_t x=a.size();x-->0;)
result[y][x]=a[x][y];
} return result;
}

template<class Ar>Ar rot1(Ar a){ // rotate cw, assume
// row-major, row counts down, columns count right
std::reverse(a.begin(),a.end());
return zip(a);
}
template<class Ar>Ar rot2(Ar a){ // reverse of rot1
a=zip(a);std::reverse(a.begin(),a.end());
return a;
}

template<class Fn>auto each(Fn f){//f must have type (T -> T)
return [f](auto&& ar){
for(auto& elem:ar)elem=f(std::move(elem));
return ar;
};
}
auto zipeach=each(zip<v2>);

template<class Fn>auto twice(Fn f){//f must have type (T -> T)
return [f](auto&& ar){
return f(f(std::forward<decltype(ar)>(ar)));
};
}

template<class Ar>std::vector<Ar>allrot2(Ar a,std::vector<Ar>& result){
// calculate all (4) rot of the 2D array (a) and append to (result).
result.push_back(std::move(a));
for(int i=3;i-->0;)result.push_back(rot1(result.back()));
return result;
}
auto rot1each=each(rot1<v2>);

std::vector<v3>allrot(v3 a){
std::vector<v3>result;
for(int i=0;i<4;++i){
/*
auto r2a=allrot2(a);
result.insert(result.end(),
std::make_move_iterator(r2a.begin()),
std::make_move_iterator(r2a.end()));
*/
allrot2(a,result);
a=rot1each(a);
}
a=zipeach(rot1(zipeach(a)));
allrot2(a,result);
a=each(twice(rot1<v2>))(a);
allrot2(a,result);
return result;
}

void pr(v3 const&a){
for(v2 const&plane:a){
for(v1 const&row:plane){
for(int x:row)std::cout<<x;
std::cout<<'\n';
} std::cout<<'\n';
} std::cout<<"=======\n";
}

// given a v2, return something with its size but all zeroes.
v2 zero(v2 x){x.assign(x.size(),v1(x[0].size())); return x;}
v3 pad (v3 x){// pad left and right with an all-zero v2.
x.insert(x.begin(),zero(x[0]));//at begin
x.push_back(x[0]);//at end-now begin is a zero()
return x;}
v3 trim(v3 x){//the array (x) must not be completely empty
auto it=x.begin();auto p0=zero(x[0]);
while(p0==*it)++it;
x.erase(x.begin(),it);
while(x.back()==p0)x.pop_back();
return x;
}

template<class Fn,Fn f>v3 ap3d(v3 a){ // apply for all 3 dimensions
a=f(a); // x y z -> [x] y z
a=zipeach(a); // [x] z y
a=zip(f(zip(a))); // [x] [z] y
a=zipeach(a); // [x] y [z]
a=zip(f(zip(a))); // [x] [y] [z]
return a;
}
auto trim3d=ap3d<decltype(&trim),&trim>;

std::vector<v3> expand(std::vector<v3> cubes){
std::vector<v3> result;
for(v3&cube:cubes){
size_t const nx=cube.size(),ny=cube[0].size(),nz=cube[0][0].size();
for(size_t x=nx;x-->0;)
for(size_t y=ny;y-->0;)
for(size_t z=nz;z-->0;){
if(cube[x][y][z])continue;
if(
(x&&cube[x-1][y][z])||(x!=nx-1&&cube[x+1][y][z])||
(y&&cube[x][y-1][z])||(y!=ny-1&&cube[x][y+1][z])||
(z&&cube[x][y][z-1])||(z!=nz-1&&cube[x][y][z+1])
){
result.push_back(cube);
result.back()[x][y][z]=true;
result.back()=trim3d(std::move(result.back()));
}
}
}
return result;
}

int main() {
std::vector<v3> a={{{{1}}}};
int n;std::cin>>n;
++n;//1-based indexing ==> 0-based indexing
--n;while(n-->0){
a=expand(a);
std::sort(a.begin(),a.end());
a.erase(std::unique(a.begin(),a.end()),a.end());
}
long long ans=0;size_t constexpr NCUBEROT=24;
for(auto&cube:a){
assert(!cube.empty());
auto rots=allrot(std::move(cube));
assert(rots.size()==NCUBEROT);
++ans;//i==0
for(size_t i=1;i<NCUBEROT;++i)
ans+=rots[0]==rots[i];
}
assert(ans%NCUBEROT==0);
std::cout<<ans/NCUBEROT<<'\n';
}



Try it online!

Next sequence. I didn't check what it is, but hopefully easy.

• To the next answerer: is the "28-term linear recurrence" proven? If not, you'll need to verify the results up to n=1001, and for that, you need a program that actually computes the sequence. – NieDzejkob Mar 8 '18 at 17:07
• aw, man, the challenge is over :( – Giuseppe Mar 14 '18 at 21:17
• @NieDzejkob When OEIS has a formula without something like "conjectured" near it, I see no reason to doubt about it. – Christian Sievers Mar 15 '18 at 12:11
• @ChristianSievers Well, "gives a 28-term linear recurrence on his web page" is different from a published paper. – NieDzejkob Mar 15 '18 at 14:25
• @NieDzejkob It's from the the person who is the author of everything related to this sequence that is mentioned at the OEIS entry. But yeah, it's not a peer reviewed reult. – Christian Sievers Mar 15 '18 at 22:24

# 349. Kotlin, 774 bytes, A000607

val primes = mutableListOf<Int>   (2)
val prev   = mutableListOf<Double>(1.0)
fun sequence(n: Int): Double {
if (n < prev.size)
return prev.get(n)
var sum = 0.0
for (k in (primes.last() + 1)..n) {
var prime = true
for (p in primes)
if (k % p == 0) {
prime = false
break
}
if (prime)
}
for (k in 1..n) {
var divsum = 0
for (p in primes) {
if (p > k)
break
if (k % p == 0)
divsum += p
}
sum += divsum * sequence(n - k)
}
val res = 1.0 / n * sum
return res
}
fun main() {
}


Try it online!

Next sequence!

Nothing special here other than caching values because of the immense amount of recursion. (Side note -- this is my first Kotlin program!)

• Welcome to Code Golf, and nice first answer! Just an FYI, your header links to A008472, not A000607 – caird coinheringaahing Apr 13 at 21:23
• @cairdcoinheringaahing Oops, fixed! :p – fluffyyboii Apr 13 at 21:45

# 63. Haxe, 108 bytes, A000057

function(a,n=3){while(a>0){var i=0,x=0,y=1,z;while(y>0&&i++<=n){z=x+y;x=y;y=z%n;}i==n++&&a-->0;}return n-1;}


Test it online!

Next sequence

• @geokavel Sorry, I keep forgetting to do that... :P – ETHproductions Jul 22 '17 at 22:55
• Aww crud and I had the Catalan numbers ready for cQuents, but I used it for Fibonacci instead :/ – Stephen Jul 22 '17 at 22:58

# 83. Bash, 53+165265=165318, A000014

#!/bin/sh
head -"\$index" a.txt | tail -1


requires that a.txt (https://hastebin.com/eroterefov) be in the same directory

next sequence

Also, this is my first post to the Code Golf Stack Exchange, please let me know if I messed up in any way.

• Welcome to PPCG! – Martin Ender Jul 25 '17 at 5:32
• Wouldn't the next sequence be A165318? – Skidsdev Jul 25 '17 at 8:15
• This would be an invalid answer, correct? – Husnain Raza Jul 27 '17 at 4:35
• @HusnainRaza It is, but nothing good will come from deleting an answer this far from the end of the chain. – Dennis Jul 28 '17 at 16:32
• If the values of the next current sequence (A000066) are not even known past n=13, how is one supposed to write a program to calculate them? – Husnain Raza Jul 28 '17 at 18:05

# 84. Boo, 330 bytes, A165318

def f (n):
cnt = 0
i   = 1
while true:
i++
isPrime = true
for k in range(2, i):
if i%k==0: isPrime = false
if isPrime == false: continue
divs = 0
q    = i-1
for k in range(1, i):
if q%k == 0: divs = divs+1
if (divs & (divs - 1)) != 0: continue
if cnt == n: return i
cnt++


Try it online!

Next sequence

# 85. TypeScript, 97 bytes, A000330

function f(i:number) {
let s:number=0;
for(let j:number=0;j<=i;j++){
s+=j**2;
}
return s;
}


Try it online!

Next Sequence

• Back to partitions again? Fine... – caird coinheringaahing Jul 25 '17 at 13:15
• @cairdcoinheringaahing sorry :P – Stephen Jul 25 '17 at 13:15

# 88. Go, 386 bytes, A000016

For those using graduation script, SE translates tabs into spaces.

import . "math"
func gcd (a, b int) int {
for b != 0 { c := b; b = a % b; a = c }
return a
}
func phi (n int) int{
r := 1
for i := 2; i < n; i++ { if gcd (i, n) == 1 { r++ } }
return r
}
func f (n int) int {
s := 0.
for i := 1; i <= n; i++ {
if (i % 2 == 1) && (n % i == 0) {
s += (float64(phi(i)) * Pow(2., float64(n) / float64(i))) / float64(2 * n)
}
}
return int(s)
}


Try it online!

Next Sequence.

• Can anybody explain the difference between all these sequences with the same name but different values? A000033, A000159, A000181, A000185, A000222, A000386, A000425, A000426, A000450, A058085, A058086, A058089, A058090 – Engineer Toast Jul 25 '17 at 16:22
• @EngineerToast the difference is the offset (what that means exactly I dunno) – Stephen Jul 25 '17 at 16:40
• @StepHen Ah, thanks! I hadn't noticed that. These tables may prove relevant, then. I believe the coefficients on OEIS are given in the form k,n. I think they're related to seating couples at a table. – Engineer Toast Jul 25 '17 at 17:29

# 40. Rust, 3416 bytes, A000001

The rules seem to imply hardcoding the first 1001 cases is fine.

EDIT: I’m editing this post to give some commenters the chance to adjust their vote on it.

static COUNT: [i32; 1001] =
[0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2,
1, 15, 2, 2, 5, 4, 1, 4, 1, 51, 1, 2, 1, 14, 1, 2, 2, 14, 1, 6, 1, 4,
2, 2, 1, 52, 2, 5, 1, 5, 1, 15, 2, 13, 2, 2, 1, 13, 1, 2, 4, 267, 1,
4, 1, 5, 1, 4, 1, 50, 1, 2, 3, 4, 1, 6, 1, 52, 15, 2, 1, 15, 1, 2, 1,
12, 1, 10, 1, 4, 2, 2, 1, 231, 1, 5, 2, 16, 1, 4, 1, 14, 2, 2, 1, 45,
1, 6, 2, 43, 1, 6, 1, 5, 4, 2, 1, 47, 2, 2, 1, 4, 5, 16, 1, 2328, 2,
4, 1, 10, 1, 2, 5, 15, 1, 4, 1, 11, 1, 2, 1, 197, 1, 2, 6, 5, 1, 13,
1, 12, 2, 4, 2, 18, 1, 2, 1, 238, 1, 55, 1, 5, 2, 2, 1, 57, 2, 4, 5,
4, 1, 4, 2, 42, 1, 2, 1, 37, 1, 4, 2, 12, 1, 6, 1, 4, 13, 4, 1, 1543,
1, 2, 2, 12, 1, 10, 1, 52, 2, 2, 2, 12, 2, 2, 2, 51, 1, 12, 1, 5, 1,
2, 1, 177, 1, 2, 2, 15, 1, 6, 1, 197, 6, 2, 1, 15, 1, 4, 2, 14, 1,
16, 1, 4, 2, 4, 1, 208, 1, 5, 67, 5, 2, 4, 1, 12, 1, 15, 1, 46, 2, 2,
1, 56092, 1, 6, 1, 15, 2, 2, 1, 39, 1, 4, 1, 4, 1, 30, 1, 54, 5, 2,
4, 10, 1, 2, 4, 40, 1, 4, 1, 4, 2, 4, 1, 1045, 2, 4, 2, 5, 1, 23, 1,
14, 5, 2, 1, 49, 2, 2, 1, 42, 2, 10, 1, 9, 2, 6, 1, 61, 1, 2, 4, 4,
1, 4, 1, 1640, 1, 4, 1, 176, 2, 2, 2, 15, 1, 12, 1, 4, 5, 2, 1, 228,
1, 5, 1, 15, 1, 18, 5, 12, 1, 2, 1, 12, 1, 10, 14, 195, 1, 4, 2, 5,
2, 2, 1, 162, 2, 2, 3, 11, 1, 6, 1, 42, 2, 4, 1, 15, 1, 4, 7, 12, 1,
60, 1, 11, 2, 2, 1, 20169, 2, 2, 4, 5, 1, 12, 1, 44, 1, 2, 1, 30, 1,
2, 5, 221, 1, 6, 1, 5, 16, 6, 1, 46, 1, 6, 1, 4, 1, 10, 1, 235, 2, 4,
1, 41, 1, 2, 2, 14, 2, 4, 1, 4, 2, 4, 1, 775, 1, 4, 1, 5, 1, 6, 1,
51, 13, 4, 1, 18, 1, 2, 1, 1396, 1, 34, 1, 5, 2, 2, 1, 54, 1, 2, 5,
11, 1, 12, 1, 51, 4, 2, 1, 55, 1, 4, 2, 12, 1, 6, 2, 11, 2, 2, 1,
1213, 1, 2, 2, 12, 1, 261, 1, 14, 2, 10, 1, 12, 1, 4, 4, 42, 2, 4, 1,
56, 1, 2, 1, 202, 2, 6, 6, 4, 1, 8, 1, 10494213, 15, 2, 1, 15, 1, 4,
1, 49, 1, 10, 1, 4, 6, 2, 1, 170, 2, 4, 2, 9, 1, 4, 1, 12, 1, 2, 2,
119, 1, 2, 2, 246, 1, 24, 1, 5, 4, 16, 1, 39, 1, 2, 2, 4, 1, 16, 1,
180, 1, 2, 1, 10, 1, 2, 49, 12, 1, 12, 1, 11, 1, 4, 2, 8681, 1, 5, 2,
15, 1, 6, 1, 15, 4, 2, 1, 66, 1, 4, 1, 51, 1, 30, 1, 5, 2, 4, 1, 205,
1, 6, 4, 4, 7, 4, 1, 195, 3, 6, 1, 36, 1, 2, 2, 35, 1, 6, 1, 15, 5,
2, 1, 260, 15, 2, 2, 5, 1, 32, 1, 12, 2, 2, 1, 12, 2, 4, 2, 21541, 1,
4, 1, 9, 2, 4, 1, 757, 1, 10, 5, 4, 1, 6, 2, 53, 5, 4, 1, 40, 1, 2,
2, 12, 1, 18, 1, 4, 2, 4, 1, 1280, 1, 2, 17, 16, 1, 4, 1, 53, 1, 4,
1, 51, 1, 15, 2, 42, 2, 8, 1, 5, 4, 2, 1, 44, 1, 2, 1, 36, 1, 62, 1,
1387, 1, 2, 1, 10, 1, 6, 4, 15, 1, 12, 2, 4, 1, 2, 1, 840, 1, 5, 2,
5, 2, 13, 1, 40, 504, 4, 1, 18, 1, 2, 6, 195, 2, 10, 1, 15, 5, 4, 1,
54, 1, 2, 2, 11, 1, 39, 1, 42, 1, 4, 2, 189, 1, 2, 2, 39, 1, 6, 1, 4,
2, 2, 1, 1090235, 1, 12, 1, 5, 1, 16, 4, 15, 5, 2, 1, 53, 1, 4, 5,
172, 1, 4, 1, 5, 1, 4, 2, 137, 1, 2, 1, 4, 1, 24, 1, 1211, 2, 2, 1,
15, 1, 4, 1, 14, 1, 113, 1, 16, 2, 4, 1, 205, 1, 2, 11, 20, 1, 4, 1,
12, 5, 4, 1, 30, 1, 4, 2, 1630, 2, 6, 1, 9, 13, 2, 1, 186, 2, 2, 1,
4, 2, 10, 2, 51, 2, 10, 1, 10, 1, 4, 5, 12, 1, 12, 1, 11, 2, 2, 1,
4725, 1, 2, 3, 9, 1, 8, 1, 14, 4, 4, 5, 18, 1, 2, 1, 221, 1, 68, 1,
15, 1, 2, 1, 61, 2, 4, 15, 4, 1, 4, 1, 19349, 2, 2, 1, 150, 1, 4, 7,
15, 2, 6, 1, 4, 2, 8, 1, 222, 1, 2, 4, 5, 1, 30, 1, 39, 2, 2, 1, 34,
2, 2, 4, 235, 1, 18, 2, 5, 1, 2, 2, 222, 1, 4, 2, 11, 1, 6, 1, 42,
13, 4, 1, 15, 1, 10, 1, 42, 1, 10, 2, 4, 1, 2, 1, 11394, 2, 4, 2, 5,
1, 12, 1, 42, 2, 4, 1, 900, 1, 2, 6, 51, 1, 6, 2, 34, 5, 2, 1, 46, 1,
4, 2, 11, 1, 30, 1, 196, 2, 6, 1,10,1,2,15,199];

fn count(i: usize) -> i32 { COUNT[i] }


Try it online!

• Hardcoding in a language as dedicated to computation as rust... you earned my downvote. – Leaky Nun Jul 22 '17 at 11:22
• "Voting up a question or answer signals to the rest of the community that a post is interesting, well-researched, and useful, while voting down a post signals the opposite: that the post contains wrong information, is poorly researched, or fails to communicate information." I wouldn't necessarily upvote this because hardcoding isn't interesting but I don't think it deserves downvotes just because it isn't a creative solution – Poke Jul 28 '17 at 18:32
• Note that counting finite groups of order n is a highly non-trivial problem, and any serious attempt to write an answer here that isn’t O(silly(n)) would take hours/days of coding, and get beaten to it by some bullshit Mathematica-oid that has a built-in for it, which, surprise, absolutely would cache the first 1001 cases too. – Lynn Jul 28 '17 at 18:55
• Well then, seeing your point I will reverse my downvote, but apparently I can't un-downvote until this post is edited again. – user41805 Jul 28 '17 at 19:35
• I see your point with that, and though I don't like having languages being "wasted" to downvotes, I do see your point with the built-ins. If you edit the post I'll revert my downvote. – hyper-neutrino Jul 30 '17 at 0:10

# 92. Thue, 93 bytes, A001733

0::=~7
1::=0
2::=0
3::=~10
4::=aa
5::=~12
6::=~13
7::=~21
8::=aaa
9::=88a
a::=~1
b::=:::
::=
b


This does hardcode the values, but that shouldn't be a problem, as it is not possible to encode a number in base -1.

Next sequence

• 7 in base -1 is 1010101010101 – hyper-neutrino Jul 31 '17 at 0:26
• How is that true? – pppery Jul 31 '17 at 0:28
• The n+1-th last digit has place value -1 ** n, so since -1 ** n is -1 if n%2 else 1, every other digit is 1 (technically that's not in the sequence so you're not wrong :P but just being a nitpick xD) – hyper-neutrino Jul 31 '17 at 0:36

# 96. Common Lisp, 236 bytes, A000478

(defun power(m n)
(let ((result 1))
(dotimes (count n result)
(setf result (* m result)))))
(defun solve(n) (+ (- (/ (+ 7 n (* (+ 6 n) (+ 6 n))) 2) (* (+ .5 (/ (+ 6 n) 4)) (power 2 (+ 5 n)))) (/ (power 3 (+ 6 n)) 6)))


Try it online!

Some code copied from this StackOverflow question. This is a trivial conversion of the formula specified in the comments of the sequence into lisp.

Next sequence

• Perhaps I'm disobeying my own advice, but the next sequence shouldn't be too hard. – pppery Jul 31 '17 at 1:52
• Max Alekseyev, can we get a formula that's not just >=? xD – Stephen Jul 31 '17 at 2:01
• @StepHen You're twelve years too late to ask ... – pppery Jul 31 '17 at 2:07
• @StepHen Why don't you just do what the original researchers did, and write an exhaustive search program on IBM S/360 cards? – KSmarts Jul 31 '17 at 17:00
• @MDXF The papers in the "links" section provide more information. There doesn't appear to be a simple way to do it (with the algorithm I'm working on, I doubt more than the first 2 or 3 terms will fit in TiO's time limit), but it's not impossible. – KSmarts Aug 2 '17 at 14:34