26
3
We see a lot of challenges here asking for a function to create a sequence from the OEIS. While these challenges are fun, as a programmer I see an opportunity for automation.
Your challenge is to make a program that takes the index of a sequence (e.g. A172141) and some integer n (e.g. 7), and pulls the appropriate value from the appropriate webpage.
I/O
As mentioned, your program should take a sequence index and some value n as input and output the nth term in that sequence. You accept any index in the sequence's B-files. If the index is greater than the largest index listed in the B-files you may throw an exception or output whatever you choose (these are not in the test cases). Standard methods of input and output are permitted.
Restrictions on web use
You should not access any websites other than https://oeis.org and http://oeis.org. This includes url shorteners, your own personal website, and this question itself. If you would like to access some other website and you believe that it is not unfair to allow you to do so, you can leave a comment and I will arbitrate.
Scoring
This is a code golf challenge so the program with the least bytes used in its source code wins. Standard loopholes are disallowed.
Test Cases
Assuming that your machine has proper internet connection and the OEIS servers are up and running the following inputs and outputs should correspond.
A172141, 7 -> 980
A173429, 4 -> 276
A190394, 6 -> 16
A002911, 11 -> 960
A052170, 3 -> 24
A060296, 8 -> 3
A178732, 5 -> 27
A000001, 1 -> 1
A000796, 314 -> 3
A001622, 162 -> 8
A002206, -1 -> 1
Tip
- When accessing the B-files
http://oeis.org/b<A-number>.txt
will redirect to the proper B-file.
1It's not clear to me up which indices we have to support. The last two test cases hint that we should query, e.g.,
oeis.org/A000796/b000796.txt
rather thanoeis.org/A000796/list
. Is the fomer what you mean by B-files? In that case, mentioning the offset is rather superfluous. – Dennis – 2016-08-10T16:35:44.303@Dennis Sorry I think that was the result of multiple edits over time. I will edit for clarity, – Post Rock Garf Hunter – 2016-08-10T16:38:52.207
I think this should have spent more time in the sandbox, because I'm sure it wasn't your intention that sequences without B-files should be unsupported. – Peter Taylor – 2016-08-10T18:24:35.133
1@PeterTaylor according to the OeisWiki "If no b-file has been uploaded for a particular sequence, the server generates a b-file containing exactly the terms displayed, for convenience with automated tools." so there should be a B-file for every sequence. Although you may be right about prematurely moving this challenge from the sandbox. – Post Rock Garf Hunter – 2016-08-10T18:29:02.010
1Well, I've learnt something useful today. – Peter Taylor – 2016-08-10T20:07:41.623
What is that last testcase with a negative index? – Scimonster – 2016-08-10T22:09:43.910
@Scimonster The list of Gregory Coefficients A002206 starts at index -1. That would be the first item listed.
– Post Rock Garf Hunter – 2016-08-10T22:27:01.563relevant tool – Downgoat – 2016-08-10T23:29:31.517