2
\$\begingroup\$

There are lots of challenges that just pick a sequence from oeis and ask you to print n-th number or first n numbers or whatever.

It's time to stop automate!

Task

Your task is to parse a sequence page from oeis.org and print its index, description and example values. The page's index should be chosen and random, selected uniformly from the range [1-289361].

Example outputs (formatted with newline as a separator):

A034434
Multiplicity of highest weight (or singular) vectors associated with character chi_46 of Monster module.
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 3, 7, 12, 21, 38, 60, 102, 165, 265, 416, 660, 1015, 1574, 2405, 3665, 5535, 8364, 12512, 18726, 27862, 41391, 61240, 90541, 133381, 196395, 288534, 423656, 621219, 910885, 1334634

A38246
Triangle whose (i,j)-th entry is binomial(i,j)*5^(i-j)*4^j.
1, 5, 4, 25, 40, 16, 125, 300, 240, 64, 625, 2000, 2400, 1280, 256, 3125, 12500, 20000, 16000, 6400, 1024, 15625, 75000, 150000, 160000, 96000, 30720, 4096, 78125, 437500, 1050000, 1400000, 1120000, 537600, 143360, 16384, 390625

A212813
Number of steps for n to reach 8 under iteration of the map i -&gt; <a href="/A036288" title="a(n) = 1 + integer log of n: if the prime factorization of n is n = Product (p_j^k_j) then a(n) = 1 + Sum (p_j * k_j) (cf. A...">A036288</a>(i), or -1 if 8 is never reached.
-1, -1, -1, -1, -1, -1, 1, 0, 2, 1, 2, 1, 3, 2, 3, 3, 4, 3, 3, 2, 3, 3, 3, 2, 3, 4, 2, 2, 4, 3, 4, 3, 4, 3, 4, 3, 5, 4, 5, 2, 5, 4, 5, 4, 2, 5, 3, 2, 4, 4, 4, 4, 3, 2, 5, 3, 4, 4, 5, 4, 5, 4, 3, 4, 4, 5, 5, 4, 3, 4, 5, 4, 4, 3, 3, 3, 4, 4, 4, 3, 4, 5, 5, 4, 4, 6, 5, 4, 4, 3, 4, 3, 5, 5, 4, 3, 6, 5, 4, 4, 5, 4, 4, 3, 4, 4, 4, 3, 5, 4, 6, 4, 5, 4, 5, 4, 3, 5, 4

A155181
a(n)=5*a(n-1)+a(n-2), n&gt;2 ; a(0)=1, a(1)=4, a(2)=20 .
1, 4, 20, 104, 540, 2804, 14560, 75604, 392580, 2038504, 10585100, 54964004, 285405120, 1481989604, 7695353140, 39958755304, 207489129660, 1077404403604, 5594511147680, 29049960142004, 150844311857700, 783271519430504

A227356
Partial sums of <a href="/A129361" title="a(n) = sum{k=floor((n+1)/2)..n, F(k+1)}.">A129361</a>.
1, 2, 5, 10, 20, 36, 65, 112, 193, 324, 544, 900, 1489, 2442, 4005, 6534, 10660, 17336, 28193, 45760, 74273, 120408, 195200, 316216, 512257, 829458, 1343077, 2174130, 3519412, 5696124, 9219105, 14919408, 24144289

Example, ungolfed, python script:

import requests
import random
seq = 'A%s' % `random.randint(1,289361)`.zfill(6)
page = requests.get('http://oeis.org/%s' % seq)
print_next = False
content = []
for line in page.text.split('\n'):
    if print_next:
        print_next = False
        content.append(line)
    if '<td width="710' in line or '<td valign=top align=left>' in line:
        print_next = True
print seq
print content[0].lstrip()
print content[1].lstrip()[4:-5]

Rules

  • oeis.org states, that there are 289361 sequences right now. You should not try to parse pages with higher index.
  • Your program should uniformly choose a random page.
  • Your program may produced undefined behavior if it randomly chooses to parse an oeis page that is reserved or does not contain a sequence (see A288145)
  • Trailing white space is acceptable.
  • You must remove leading white space and the outermost html tags from each line of your output. (i.e., the example values are wrapped in <tt><tt/>, which must be removed, but the description sometimes contains tags such as <href> within the text. Such tags do not need to be handled (see A195534)).
  • You do not have to handle html escapes (see A219225)
  • You do not need to print leading zeroes in the index. (e.g. A1 and A000001 are both acceptable). This is because oeis.org itself allows you to do either, as in, http://oeis.org/A1 and http://oeis.org/A000001 are both valid URLs that point to the same page.
  • You may return/print the "lines" in one of the following formats:
    • As an array/list with three elements
    • As a string separated by some separator. However, the separator must not appear in any of the "lines" (the index, the description, or the example values). In addition, this separator must be consistent (you can't select a separator based on the content of the "lines").
  • The meta definition of uniformly random applies.
  • Standard loopholes apply.

This is , so shortest code (in bytes) wins.

\$\endgroup\$
4
  • \$\begingroup\$ Very related \$\endgroup\$
    – Wheat Wizard
    Jul 13, 2017 at 15:24
  • \$\begingroup\$ @WheatWizard Yep. But task is different \$\endgroup\$ Jul 13, 2017 at 15:25
  • \$\begingroup\$ This needs to specify precisely what formats are permitted and deal with edge cases including particularly gaps in the sequence IDs (e.g. oeis.org/A288145 ) \$\endgroup\$ Jul 13, 2017 at 16:12
  • \$\begingroup\$ @PeterTaylor I think, that edits made to post are specify it all \$\endgroup\$ Jul 14, 2017 at 14:37

2 Answers 2

4
\$\begingroup\$

CJam (61 bytes)

"oeis.org/search?fmt=text&q=id:A"289361mr)s+gN%{1=s"ISN"&},N*

No online demo available because the use of g is restricted by both online testers for security reasons.

I'm still not convinced that the output format is clearly specified, but since I seem to be in a minority I'm exploiting its gaps for golfiness. There is no leading whitespace or outer HTML tag to remove in the output.

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

Python 3, 198 bytes

from requests import*
import random,html
s='A%s'%str(random.randint(1,289355))
print(s)
t=get('http://oeis.org/%s'%s).text.split('\n')
print(html.unescape(t[95].strip()))
print(t[116].strip()[4:-5])

This works for everything I've tried so far, but since it hard-codes the line indices, please tell me if it breaks on anything (that isn't an unfilled reserved spot).

-9 bytes thanks to Dead Possum

\$\endgroup\$
2
  • \$\begingroup\$ You may remove .zfill(6). Turns out, that leading zeros are not necessary \$\endgroup\$ Jul 14, 2017 at 14:39
  • \$\begingroup\$ @DeadPossum Oh cool, thanks. \$\endgroup\$
    – hyper-neutrino
    Jul 14, 2017 at 22:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.