Your challenge: Connect to the Online Encyclopedia of Integer Sequences OEIS.org, access any random valid sequence, output it's ID, and ouput all of the members of the sequence provided by the OEIS entry. The only website you're allowed to connect to is OEIS.org.

Hints: Sequences are found in URLs such as http://oeis.org/A280629, however a more easily parseable version is found at URLs such as http://oeis.org/search?q=id:A280629&fmt=text. Every present and future sequence matches the regex "[A-Z]\d{6}". (The regex is there to describe what an ID looks like. There are a lot of invalid sequences that match it, too). The webcam (http://oeis.org/webcam) feature of OEIS generates random sequences, but you'll have to find a way to change the dropdown menu from 'best sequences' to 'all sequences' to use it.

Example output:

1, 1, 7, 139, 6913, 508921, 57888967, 9313574419, 1984690709953, 547467006437041, 188946742298214727, 79783392959511537499, 40498043815904027702593, 24314800861291379306213161, 17047720745682515427867108487, 13802952030641885344209574247779, 12780883488499783875309105315925633, 13420910251496135926622603184056054881, 15863354775169518855398667975850797997447, 20966527201075972453953302254528386060431659

Every existing sequence has to have a chance of being outputed, it does not have to be an equal chance.

Your program should continue to function properly regardless of future sequences being added. Even though all IDs presently start with A, there will eventually be a sequence B000001 after all the A sequences run out. You can assume that there will be no more sequences after Z999999 is defined, but you do have to assume that it will eventually be defined.

An invalid sequence, which your program should never output, is one that doesn't exist. You may treat sequences with no given members (such as A280611 either as invalid or give just the sequence ID and nothing else or a falsy value, but you must be consistent.

This is , fewest bytes wins!

  • \$\begingroup\$ Your regex isn't quite right - sequences can't end with 000000. Additionally, is outputting a valid sequence that doesn't exist yet acceptable? \$\endgroup\$ – Mego Jan 8 '17 at 8:36
  • 1
    \$\begingroup\$ What about "sequences" like this one. How shall we handle those? Do we have to check if the entry contains a sequence, and if not find another entry that does? This makes it a lot harder/cumbersome. \$\endgroup\$ – Stewie Griffin Jan 8 '17 at 8:39
  • \$\begingroup\$ When the sequences names have leading 0, can we omit those 0? (for instance, A15 instead of A000015) \$\endgroup\$ – Dada Jan 8 '17 at 9:54
  • \$\begingroup\$ Arg, this is impossible in JS \$\endgroup\$ – TrojanByAccident Jan 8 '17 at 22:40

Perl, 93 bytes

$u=chr(65+rand 26).sprintf("%06d",rand 1e6),$_=`curl oeis.org/$u`while!/tt>(.*?)</;say"$u

Run it with -E flag (and I suggest redirecting STDERR, as curl prints its progression on it):

perl -E '$u=chr(65+rand 26).sprintf("%06d",rand 1e6),$_=`curl oeis.org/$u`while!/tt>(.*?)</;say"$u
$1"' 2> /dev/null

-$u=chr(65+rand 26).sprintf("%06d",rand 1e6) generates a random name,
-$_=curl oeis.org/$u tries to retrieve the sequence,
-/tt>(.*?)</ checks if a tag <tt> is present on the page (it's only present on valid pages). If so, it stores the sequence's elements in $1. And if not, the while keeps looping.
-say"$u\n$1" outputs the sequence's name and its elements.

  • \$\begingroup\$ Do you know of an online interpreter where this works? \$\endgroup\$ – Pavel Jan 8 '17 at 10:27
  • \$\begingroup\$ The easiest is to run it in a unix terminal... It does potentially a lot of http request, so I don't think there is an online interpreter capable of running it.. \$\endgroup\$ – Dada Jan 8 '17 at 10:32
  • \$\begingroup\$ This actually fails for oeis.org/A280611 ... \$\endgroup\$ – TrojanByAccident Jan 8 '17 at 20:41
  • \$\begingroup\$ @TrojanByAccident I don't think it does: replace $u=chr(65+rand 26).sprintf("%06d",rand 1e6) by $u=A280611 and you'll have the right output... \$\endgroup\$ – Dada Jan 8 '17 at 20:45
  • \$\begingroup\$ @Dada well, I'm no expert on Perl, and I can't run it, as I'm on Windows, but that page contains <tt> tags, so... \$\endgroup\$ – TrojanByAccident Jan 8 '17 at 20:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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