question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposed OEIS adapter for searching integer sequences

See original GitHub issue

Todo

  • define query format
  • implement query format using an external adapter
  • fix syntax highlighting
  • add oeis cheat sheet with query format description and examples
  • Occasional formatting mishaps BAD instead of GOOD
  • Bibliography sources should be names (ignore and consolidate different dates with same name)
  • When stress testing: curl cheat.sh/oeis/$RANDOM/mathematica continually ended up with misplaced error messages (seemingly from grep)

Adapter:

  • Remove pygmentize calls
  • Add language selection for code samples
  • Limit number of terms shown for sequence sample (implemented?)

cheat.sheets:

  • add OEIS languages names

Details

The On-Line Encyclopedia of Integer Sequences is a great resource for programmers. It’d be cool to browse sequences from the command line and potentially get code samples to copy and paste. I have a working prototype of the script here. Currently it can either take one argument or many. If many are supplied, a list of potential sequence matches is returned, of one argument is supplied, then the sequence with that ID and a colorized code segment are returned.

Example usage finding a sequence by pattern

curl cht.sh/oeis/1+1+2+1+1+3+3+1

A007318: Pascal’s triangle read by rows: C(n,k) = binomial(n,k) = n!/(k!*(n-k)!), 0 <= k <= n. 1, 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, 4, 6, 4, 1, 1, 5, 10, 10, 5, 1, 1, 6, 15, 20, 15, 6, 1, 1, 7, 21, 35, 35, 21, 7, 1, 1, 8, 28, 56, 70, 56, 28, 8, 1, 1, 9, 36, 84, 126, 126, 84, 36, 9, 1, 1, 10, 45, 120, 210, 252, 210, 120, 45, 10, 1, 1, 11, 55, 165, 330, 462, 462, 330, 165, 55, 11, 1

A061554: Square table read by antidiagonals: a(n,k) = binomial(n+k, floor(k/2)). 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, 6, 4, 4, 1, 1, 10, 10, 5, 5, 1, 1, 20, 15, 15, 6, 6, 1, 1, 35, 35, 21, 21, 7, 7, 1, 1, 70, 56, 56, 28, 28, 8, 8, 1, 1, 126, 126, 84, 84, 36, 36, 9, 9, 1, 1, 252, 210, 210, 120, 120, 45, 45, 10, 10, 1, 1, 462, 462, 330, 330, 165, 165, 55, 55, 11, 11, 1, 1

Example usage looking up a particular sequence by ID

curl cht.sh/oeis/A007318

ID: A007318
Pascal’s triangle read by rows: C(n,k) = binomial(n,k) = n!/(k!*(n-k)!), 0 <= k <= n.

1, 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, 4, 6, 4, 1, 1, 5, 10, 10, 5, 1, 1, 6, 15, 20, 15, 6, 1, 1, 7, 21, 35, 35, 21, 7, 1, 1, 8, 28, 56, 70, 56, 28, 8, 1, 1, 9, 36, 84, 126, 126, 84, 36, 9, 1, 1, 10, 45, 120, 210, 252, 210, 120, 45, 10, 1, 1, 11, 55, 165, 330, 462, 462, 330, 165, 55, 11, 1

(AXIOM) )set expose add constructor OutputForm pascal(0, n) == 1 pascal(n, n) == 1 pascal(i, j | 0 < i and i < j) == pascal(i-1, j-1) + pascal(i, j-1) pascalRow(n) == [pascal(i, n) for i in 0…n] displayRow(n) == output center blankSeparate pascalRow(n) for i in 0…20 repeat displayRow i (PARI) C(n, k)=binomial(n, k) (Python) def C(n, k): if k < 0 or k > n: return 0 res = 1 for i in range(k): res = (n - i) return res def C(n, k): from numpy import prod; return prod([(n-j)/(j+1) for j in range(k)]) def C(n, k): from functools import reduce; return reduce(lambda x, y: x(n-y) (Haskell) a007318 n k = a007318_tabl !! n !! k a007318_row n = a007318_tabl !! n a007318_list = concat a007318_tabl a007318_tabl = iterate ( (Maxima) create_list(binomial(n, k), n, 0, 12, k, 0, n); (Sage) def C(n, k): return Subsets(range(n), k).cardinality() (MAGMA) (GAP) Flat(List([0…12], n->List([0…n], k->Binomial(n, k))));

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:30 (17 by maintainers)

github_iconTop GitHub Comments

2reactions
chubincommented, Jul 14, 2020

How would you suggest these special search arguments be specified?

We can specify arguments either inline 1+2+3+author:Stanley or as URL arguments: 1+2+3?author=Stanley

I tend to the first option.

What should be the default behavior? Should we only print sequences that start with the numbers given? Should we print sequences that contain a sub-sequence of the numbers given?

If we simulate grep semantics, it should be “contain” instead of start, and to force the “start” search, the sequence must be prepended with ^

How many terms should be printed out for each sequence (currently 10) or how many digits/chars??

I think 10 is ok, but we need to support an additional parameter for longer output (?n=20) and maybe for ranges

2reactions
chubincommented, Jul 14, 2020

I’ve merged and deployed it; it looks much better now:

$ curl cht.sh/oeis/29069/mathematica
(*
 * ID: A029069
 * Expansion of 1/((1-x)*(1-x^4)*(1-x^5)*(1-x^12)).
 *
 * 1, 1, 1, 1, 2, 3, 3, 3, 4, 5, 6, 6, 8, 9, 10, 11, 13, 15, 16, 17, 20,
 * 22, 24, 25, 29, 32, 34, 36, 40, 44 ...
 *)

CoefficientList[Series[1/((1-x)(1-x^4)(1-x^5)(1-x^12)),{x,0,60}],x] (* [1] *)

(*
 * [1] [Harvey P\. Dale, Aug 11 2011]
 * [https://oeis.org/search?q=id:A029069]
 *)

Just a minor thing to be fixed:

Sequence search ls commented like C, and highlighted like shell. The question is how we should comment it? Like shell? I understand that we can just leave it as text, without commenting it out, but actually we on cheat.sh have such a rule that text must be displayed as comments, and code as code.

We could make an exception for OEIS though, because this rule does not seem to make sense for it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The On-Line Encyclopedia of Integer Sequences® (OEIS®)
The On-Line Encyclopedia of Integer Sequences® (OEIS®). Enter a sequence, word, or sequence number: Hints Welcome Video. For more information about the ...
Read more >
Hints for Using The On-Line Encyclopedia of Integer ...
The main uses for the OEIS are: to identify a sequence; to obtain more terms, formulas, references, links, programs, etc. for a sequence....
Read more >
Sequence transforms - OeisWiki
Sequence transforms are operations on a subset of the set of integer sequences. Informally, they are a way of creating a new sequence...
Read more >
Index to OEIS - OeisWiki
A highly selective Index to the On-Line Encyclopedia of Integer Sequences™ (or OEIS®) · The principal sequences are marked by asterisks (*). ·...
Read more >
New OEIS Banner - OeisWiki
This design is based on Tony Noe's 2014-01-07 banner. · It takes the color from the OEIS search bar, moves the text to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found