Proposed OEIS adapter for searching integer sequences
See original GitHub issueTodo
- 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 fromgrep
)
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:
- Created 3 years ago
- Comments:30 (17 by maintainers)
Top GitHub Comments
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.
If we simulate grep semantics, it should be “contain” instead of start, and to force the “start” search, the sequence must be prepended with
^
I think 10 is ok, but we need to support an additional parameter for longer output (
?n=20
) and maybe for rangesI’ve merged and deployed it; it looks much better now:
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.